Jump to content

Lua : self.entity nil possible ?


YouGroove
 Share

Recommended Posts

I had some simple GetPosition inside a function called walk() called from UpdateWorld() :

 

 local positionPlayer = self.entity:GetPosition(true)
if positionPlayer.x < self.xminPos then
-- self:walkMinPos()
else
-- --self:walkMaxPos()
end

 

It didn't worked as i had nil for that code :

self.entity:GetPosition(true)

 

Is that normal ?

I put above code directly in UpdateWorld() instead of calling a function and it worked ?

Is something i do in bad way ? would not self.entity accessible from any function we create ?

Stop toying and make games

Link to comment
Share on other sites

Make sure you defined your walk function like:

 

function Script:Walk()
end

 

My guess is you defined it just like:

 

function Walk()
end

 

If you don't know why you need to do that then you don't have a fundamental idea of how Lua is working. Let me know and I can help explain.

 

I'f I'm wrong then we need to see the entire script.

Link to comment
Share on other sites

If you don't know why you need to do that then you don't have a fundamental idea of how Lua is working. Let me know and I can help explain.

 

I use Lua for all ennemies, my own functions, even ennemies or player calling each other scripts, i'm not so newbbie with Lua in LE3 i guess ?

 

That's simple :

same code in UpdateWordl : ok

same code in function : error nil

 

That's not first time strange things happens with LE3.

post-3271-0-37731800-1398000185_thumb.jpg

Stop toying and make games

Link to comment
Share on other sites

Where is self.xmin defined or given a value? After seeing what you have there I now think that this function is being called before you define or give xmin a value. LE doesn't do anything strange to Lua, which is why the reason is 99.9% always your usage of it and not understanding how it works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...