is it possible to store a reference to an object in a variable?
I’m working on a strategy game where I have some ships that I can send to orbit around different planets.
What I’m trying to achieve is to click on a planet and make the ships orbit around it. If I click on another planet they should orbit around the other one.
“Rotate ship around planet with xx deg/sec and yy pixels away” works wonderfully here but unfortunately I don’t know how to assign another target planet to the ships.
If I could store the target planet i clicked on in a local variable on the ship object, I could just exchange the “planet” object with the variable containing the target planet.
Is that possible somehow?
No, but you can use the “Linked objects” extensions to achieve the same result.
Use the action “Link the SHIP_TO_LINK to the PLANET object” to virtually link the ships to a planet.
Then, in the event (which need to be a “For each” event to process each ship individually) where you move the ships around the planets, you can use a condition from this extension to take only into account the planet object linked to the ship, so that the ship will turn around this particular planet.
Thanks for the quick answer, works perfectly.
I don’t know how the linking is implemended. If it is looping through all the objects in a scene checking for the link property, maybe storing a reference to a specific object in a variable could be faster in matter of game performance when there are lots of instances of an object in the game.
Perhaps this is a feature that could be implemented in the future.
In fact, I don’t think there is a big difference in term of performances.