1 in 5...

For questions about using Classic.

Post » Fri Mar 13, 2009 3:18 pm

In my game when the player jumps it makes a sound, I'd like to make that sound play only 1 time i 5 jumps (randomly) can someone help me?
B
15
S
5
G
7
Posts: 83
Reputation: 4,020

Post » Fri Mar 13, 2009 3:25 pm

[code:xw0s4b77]+Random(5)=0
>Play Sound[/code:xw0s4b77]

Random(5) returns either 0,1,2,3 or 4, so there is a 1 in 5 chance to get 0.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Fri Mar 13, 2009 3:32 pm

Create a private value for the player which counts the jumps. Leave this value at default 0. Everytime the player jumps, add 1 to this value. (Jumps)
Create another value which will be set to Random(5) + 1 on startup. (SoundTime)

Now if Jumps is equal to Soundtime => play Sound
If Jumps is equal to 5 => Set Jumps to 0 and Soundtime to Random(5) + 1

That should do the trick I guess. :)
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Fri Mar 13, 2009 3:46 pm

Thank you very much :D
B
15
S
5
G
7
Posts: 83
Reputation: 4,020


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests