Raxe88 Posted April 12, 2015 Share Posted April 12, 2015 This is my code: DeathTrigger.lua (attached to a box) Script.respawnPoint = "" --Entity "respawn point" function Script:Collision(entity, position, normal, speed) if(entity:GetKeyValue("name") == "Player") then spawnPos = self.respawnPoint:GetPosition() --entity:SetPosition(spawnPos) entity:Respawn(spawnPos) end end and FPSPlayer.lua (attached to the player) function Script:Respawn(spawnPos) self.entity:SetPosition(spawnPos) end When they collision I get this error: I have a Pivot indicating the respawn point: Line 65 is this from DeathTrigger.lua: entity:Respawn(spawnPos) From my point of view it should work. Any help? Edit: I just found it out. Turns out that this works: entity.script:Respawn(spawnPos) A little explanation would be welcome Quote Link to comment Share on other sites More sharing options...
Rick Posted April 12, 2015 Share Posted April 12, 2015 The entity and a script attached to that entity are 2 different things. You can get either from both. entity.script or (inside the script) self.entity (note that when inside a script 'self' refers to the script itself NOT the entity) The collision callback is returning to you the entity NOT the script. So in order to call the script functions attached to the entity you need to access the script variable of the entity. entity.script:Respawn() Now entities do have functions (as you see in entity:SetPosition()) but those are C++ engine commands on the entity. The scripts are different than the built-in engine functions. This whole script thing is something that didn't exist in the early days of LE but something like SetPosition() has existed since day 1. Scripting functionality was added later after the core engine functions were already there. 1 Quote Link to comment Share on other sites More sharing options...
Raxe88 Posted April 12, 2015 Author Share Posted April 12, 2015 Thanks a lot for the answer! This is something I didn't know and is important. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.