[SOLVED] Random event when game start

I am trying to make a random event for when you load the game, there’s a random chance for a Sprite to change to another
When the game is run, the spirit is ment to have a small chance to a different one
What happens is when the game is loaded is the debug text flickers between “normal” and Face"

Hi @Lewis64!

And it is normal!
Either the random number is bigger or less than or equal to 50 ( 1 chance on 2)

You must use an another GD’s function which gives you the possibility to choice between more numbers like (this is an example):
3 4 5 … 10
with instruction RandomInRange(3, 10)

A+
Xierra

1 Like

To add to what @Amigo54 said, please make sure this is done once and not multiple times (probably at the beginning of the scene) so you don’t see different results per frame.

2 Likes

Im not fully sure I fully understand, could you provide a visual, if you don’t mind

No visual, sorry but i’m trying to be clearer.

First, show us all your important events in the objective we can be more precise to bring an answer.

Thanks.

A+
Xierra

2 Likes

Sure. Tho I’ll share the whole code, for the game,

1 Like

Yikes, the random isn’t going to yield a definite result because it runs every frame. Gdevelop runs the events every frame (which is 60 times per second) so your event that isn’t controlled by a condition runs every time this happens, so you get a new random value 60 times every second and that is what causes the flicker. I recommend you add a condition to the Change Variable event. The best for easy testing will be on key released.

Edit:
But if you want it to run at the start of the scene use at the beginning of the scene.

1 Like

Alright thanks for explaining my mistake, that is appropriated.
What condition should i use, know name that would be really helpful

Do this and the change will only be run once at the very start of the scene:

3 Likes

Adding to what @MrMen said:

  1. The condition name is “At the beginning of the scene”
  2. Make those 2 subevents of the first one (the one with at the beginning of the scene"
2 Likes

It worked, thank you three for the help

1 Like

at scene start generate random number wait 0.5s and set a var to start the event that figures out what to do to 1

then

var random number = 1
AND
var Generation done = 1
then do it does the change

1 Like

I appreciate the help aswel,
However it was already solved i just can’t edit my post to make it as so

2 Likes

Hey!
I marked your post as “Solved” for you!
In the future, if you say something like “This post is solved”, it should get marked faster (as it is a manual thing).

Have a great day! :smile: