I stumbled on a strange behaviour. I don’t know if it’s a bug , intended behaviour, or if I’m doing something wrong.
I was sending a set_position message to a spaceship GO on the map. I made a typo in the ID of the Spaceship script, so the GO didn’t the message. But what did happen was that my worldmap GO got the message instead, and changed its position.
This seems really strange to me, is it intended behaviour? Or am I doing something wrong to cause this?
You cannot set the position of a component, only a game object (the ”#” notation is used to address the component part of an url). Don’t you get an error in the console?
I just tested without the component, and that works as well
go.set_position(shipPosition, "/spaceship")
But if I just use the ID of the component (which is in another GO, so obviously not reachable), it instead sets the position of my map GO, without throwing errors. The map GO has the script attached.
go.set_position(shipPosition, "#spaceship") -- This actually gets sent to the map GO
Most go.* functions operate on the game object and not the individual components. That’s why you shouldn’t specify the component part (ie after the # sign). And if you want to modify the game object the script is attached to then don’t specify a url at all.
Yes, I see that now.
Still it would be nice if there was an error when trying to specify a non existent component like this, or maybe even specifying a comonent at all when the function only handles GO:s. The dynamic nature of Lua makes it easy for typos to hide until they pop up in runtime.