Jump to content
Lunarovich

attempt to call method 'setPosition' (a nil value)

Recommended Posts

Hello! This one's driving me crazy. I can't simply understand why I get an

 

attempt to call method 'setPosition' (a nil value)

 

et the

entity:setPosition(spawnPos)

 

This two lines

print(entity:GetKeyValue("name"))
print(self.respawnPoint:GetKeyValue("name"))

 

give me a desired output:

Player name
Spawn point name

 

Here is the code...

Script.respawnPoint = "" --entity "Respawn point"
function Script:Collision(entity, position, normal, speed)
if (entity:GetKeyValue("name") == "Player") then
 spawnPos = self.respawnPoint:GetPosition()
 print(entity:GetKeyValue("name"))
 print(self.respawnPoint:GetKeyValue("name"))
 entity:setPosition(spawnPos)
end
end

 

It seems to me that in the editor everything is setup correctly:

7JUFqRr.png

Share this post


Link to post

you have to make sure you use proper capitalization with lua commands...

 

so its not:

entity:setPosition(spawnPos)

is should be:

entity:SetPosition(spawnPos)

 

edit: yes, rick beat me to it

 

Also, if you are using the internal script editor for your lua scripts, then LE commands will be blue when spelled correctly:

post-14-0-42720500-1426088757.jpg

Share this post


Link to post

@Olby I agree completely. I've started using Leadwerks only yesterday. Learned a bunch of things in a day (Lua syntax, engine program's flow and API basics). Never seen an engine so transparent, so logical and yet not sipmlistic. Best engine I've used so far, definitely.

 

That said, editor feels really clunky. No window autofocus on tab switch (always have to focus a window with a additional mouse click), as you've said, no autocomplete, even the CTRL - arrows for text navigation does not work as is case with every text editing app that I know! I've started using Atom io with a lua-language package. The only downside is that it does not color semantically valid constructs.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...