storing variables in different sprites

So i have a main sprite and 4 side sprites. The logic here is that when the left mouse is clicked on main sprite, random numbers are generated and when right click button is clicked, these numbers are stored in the side sprites one by one on each click . Can i have help with the logic for the second part where the numbers are stored in side sprites. Thanks :smiley:

I would use a variable tracking the last side sprite id used, for example:
In the scene editor:

  • Set a variable “ID” for the 4 side sprites, with ID’s 1, 2, 3 and 4 (each side sprite with a different ID of course)

In the events editor:

  • At the beginning of the scene, set a variable “last_id” = 0, because no side sprite has been modified
  • When right click is pressed, select the side sprite with ID = Variable(last_id) + 1, the next one after the last modified, and store the random number on it:

Conditions: Variable ID of Side_Sprite is = Variable(last_id) + 1 Actions: Do = Variable(your_random_generated_number) to the variable random_number of Side_Sprite

  • Also, when right click is pressed and after modifying the side sprite, do + 1 to the variable last_id, so the event should be:

Conditions: Variable ID of Side_Sprite is = Variable(last_id) + 1 Actions: Do = Variable(your_random_generated_number) to the variable random_number of Side_Sprite Do + 1 to the variable last_id

This event will select the side sprites (and set the random number) in order based on the ID variable, so you can easily order them in the scene editor through this ID variable :slight_smile:

Let me know if you need a little example :wink:

Can you give me a screenshot of the example ? :smiley: :smiley: :unamused:

I give you the example!, if you want a screenshot open the example and press the key to take screenshots :laughing:
RandomNumbers.gdg (14.7 KB)
In this example, I use text objects instead sprites so you can debug easily the values, because they are shown in the text objects :wink:

How does the Random works???

I can’t seem to get a fixed min number. Like I want to get a random number between 1 and 2. Instead of 0,1 and 2. :confused: :confused:

Hi there.

You can add a minimum value fairly simple. This is the “formula”:

MinNumber+Random(RandomMaxNumber)

So, if you write 10+Random(10), you will get a random number from 10 to 20. This works because random will still give you a number from 0 to 10, but you add the minimum number of 10.

So if random is 0, you have:
10+0 =10

If random is 10, you have:
10+10=20

Oh, and if you want a number between 1 and 2, then it is:
1+Random(1) because:
1+0=1;
1+1=2

Thanks for the info! You been popping up more actively than Lizard13 xD