I need get position player from my enemie script, I get the current position with this method:
function init(self)
self.id = "/level1/player/player"
print(go.get_position(self.id))
end
level1 is my collection for the level and player is other collection and player my object, the problem is when I make a new collection with name level2 or level3 etc.
how can access to player in diferent levels from my enemie script?
You do not need to be that specific with the url of the player. What you’re using is an absolute URL to the player game object. If both the player and the enemy are created/exist in the same place in the hierarchy of game objects it should be enough use a relative URL, like this:
I can do print(go.get_position(“/foobar/player”)) to get the position of the player game object.
In your original question you had an additional “level1” in the URL but I cannot see that in the screenshot that you shared. If you have multiple levels the common practice is to have each level in a separate collection and reference them from collection proxies and only load the current level.
“level1” is the top collection and I put level1 collection in main collection.
following your example i get this print(go.get_position(“/player/player”)) but is not working, I put my code in script1 in enemie1.
Do you really want all of the levels loaded at once? Or do you want to load one level at a time?
If you actually want to have all levels (ie collections) loaded at once then yes, you need to explicitly define the full path to the player game object (/level1/player/player). In that case you need to somehow be able to tell the script which path to use. You can use this via message posting or via a Lua module.
If you only want one level loaded at a time then stick all of the levels into collection proxies, load the level you wish to play and use the /player/player URL to the player game object.