[Solved] Object with random number inside

I am trying out Gdevelop in order to develop an interactive game.

I have created an spirit object with an object variable initialized with a random number between 0 and 9.

How do I display this object on the scene showing object variable inside?

Thanks in advance!


  1. Please read the rules and don’t write your name at the end, we already see it at the top
  1. I am sorry but this doesn’t make any sense.

I am trying to figure out if it is possible to make the object variable visible on the object when placed on the scene.I need the player to see that figure.

you can do it, but you should separate things. your sprite is a sprite object. it can’t display variables unless you already paint on it. you can create 10 different sprites, with the 10 number, but you should reate all its animations 10 times this way.
what you need is an another object, a text object. that can display values of variables (as a text). create it with the sprite object, link them together and so on. you find some info about this it he forum.

Thanks! I found the solution in the forum as you suggested.


Would you mind sharing the link to the forum. I’m trying to do the same for a maths game and have found it had to overlay the text object on top of a sprite and make it behave the same way. Thank you.

If do you have only one sprite and one text object, you don’t have to do anything special. just (always) allign the text object’s position to the sprite position, when the value of the variable change, update (modify the text of) the text object from the variable. and make sure the thext object Z order will be greater than the sprite’s Z order.
thats all. if you have more than one from this pair, then things will get a little more complicated. you should give more detail and things…

Thanks for the response. This is what I have done. I have multiple pairs of sprites and texts. I set the same spawn positions and force for both of them to make them move together but is seems inefficient. They are moving across the screen and I want to destroy the pair when they are shot at. At the moment when I set a colision condition for the sprite, then delete the sprite and text, but the text for all other pairs also delete. Is there a way to group them to make them act as a single object?

yes. for this we have a “Link” function for this.


but if your all other situations are done and work well without object linking, just the deletion is the problem, you can do it without linking. all you has to do is add one more sub-event below where you check the collision with the bullet or what. before delete the sprite, check if collision with the text and then delete both from that event.

This worked. Thank you.