[Solved] Add a random value to a variable

hi guys, i need help again!
how can i add a random value to my ammo variable, i would like the character when it collides with the ammo crate to add a random value from 5 to 20 to the ammo text variable.

Hi, you can use RandomInRange(5, 20) as a value.

1 Like

Uploading: Screenshot 2022-03-29 02.21.22.png…



these are my events, with random in range it does not work or rather it is I who perhaps am not understanding.
I would like the player when it collides with ammunition adds a random value between a minimum value and a maximum value. example between 5 and 20.
and that the value that was generated appears in the text created when opening the ammo box, adding everything to the variable ammo totals.

I hope I was clear, English is not my first language.

Can you explain what is happening?

What I can read is if player hits a fully opaque munizioni1, it changes the animation (to open box?) and adds a text box to the centre. The value of ammopistole is increase by random value (from 2-5)

Nowhere in that event do you set the text to how much ammo was collected.

Do you want text_ammofound to show how much ammo was collected? If so, assign the random amount to a variable and then include that variable’s value to text_ammofound’s text box, as well as adding add it to ammopistole.

As a note, you can use VariableString(ammopistole) instead of ToString(Variable(ammopistole)). GDevelop will cast the variable to a string as it gets used without changing it’s type.

thank you very much mr.men it was just what I was looking for. I managed to solve