Creat a %chance variable

Hello i would like to creat a new variable to random the creation of an object (shield) on a floor but only one per floor, the floor ar not at the same height
i would like somthing like 1/40 chance to pop per floor

use random (39), it will give you a number between 0 and 39 each one has 1/40 chance to be the result :smile:

ok and how can i spawn them on the platform? the platform are random too

sorry don’t understand, what do you mean with spawn?

You will probably need a “For each” event.

For each platform object, 
          random(39) = 22              Create shield 
                                       Put shield around platform
1 Like

ok i could work but how do you do this on gdevelop ? there are only for all object

1 Like

For each is a special event. Try a right-click or the big blue + button.

How about start at the beginning:

Just an idea.

how do you do random i didn’t find it

Search “random” in the expressions editor (blue button on the right) when you assign a value to a variable:

I am ashamed can u correct me plz?

1 Like

i would do
for each platform object
nothing → do scene variable chance=Random (39)
then the action you have as the number of shield objects = Random(39)
i would change by
variable(chance) = 22 → create SHIELD .

22 has 1/40 % chance to be the random number

1 Like

it working but it somtimes appear do i have to put trigger once somewhere?

1 Like

the check of chance=22 should be a subevent of the for each

so know there are shield everywhere i think it s because it repeat for each platform until creating a shield

yes you are, you should add to your platform an object variable, for example has_shield and set to 1 when you put a shield then check if shieldchance=22 and has_shield=0
That should work

ok but if has_shield is =1 so it can not be =0

at the beginning of scene you set =0 the object variable has_shield of each platform, meaning they have no shield(you can use the number you want but one to represent no shield and other shield on plat form.
So in the loop for each object platform you
check if shieldchance=22 and has_shield=0, if it is you add a shield and set has_shield=1 so you won’t create another shield on this platform.

hello i didn’t know how to to set a variable to each platform cause when i m puting this var it s for all the platforms so i did it with a timer it have ± the save result

ty for all

1 Like

a last question how can i do to spawn the shield outside the screen ?