Jump to content

Cannot use Player in script property


thehankinator
 Share

Recommended Posts

I have a simple script like the one below applied to a Pivot. I've dragged my player entity into the "Target" property. When the Start function is called it prints out "target=nil". If I drag some other entity into the Target property I get something like "target=userdata: 0x04245938", which is what I was expecting when my Target is Player. Is there something special about the Player entity?

 

 

Script.target = nil --Entity "Target"

function Script:Start()
  System:Print("target="..tostring(self.target))
end

Link to comment
Share on other sites

I've not decided what this means yet but I've modified my Start function to search for the player entity. It finds it! So I know the player entity exists at the time Start is executed.

 

function Script:Start()
 System:Print("target="..tostring(self.target))

 for x=0,App.world:CountEntities()-1 do
   local entity = App.world:GetEntity(x)
   if entity:GetKeyValue("name") == "Player" then
     System:Print("entity="..tostring(entity))
   end
 end
end

Link to comment
Share on other sites

The player is the prefab that comes with LE(although I did add a weapon). I have deleted the pivot and created a new one then added the script.

 

Thinking about all this, I tried deleting the player entity from the scene and re-adding it. This cleared up the issue! I guess I should have tried that hours earlier.

 

Thanks again

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...