How do I create a code blocks code that allows a random character to pop out every time the sarcophagus is clicked. Right now the 3 characters are in the sarcophagus and set to an opacity of 0%.
Thank you in advance for your help.
How do I create a code blocks code that allows a random character to pop out every time the sarcophagus is clicked. Right now the 3 characters are in the sarcophagus and set to an opacity of 0%.
Thank you in advance for your help.
when sarcophagus is clicked
~
if random intger beetween 1 and 3 = 1
set carachter 1 opacity to 100
move carachter 1 one metre forward
~
else if random intger beetween 1 and 3 = 2
set carachter 2 opacity to 100
move carachter 2 one metre forward
~
else
set carachter 3 opacity to 100
move carachter 3 one metre forward
@Alessio_Bonini I think it would be better to generate the random number one time, store it in a variable, then check against that variable; that way you don’t end up with a situation where the 1st random is 2, the 2nd random is 1, leaving a bias towards character 3.
So just set a variable to random int between 1 and 3 and set if variable = 1 and 2 and 3. Thank you @techleapnz I thought that the random number remain the same.
As long as the random number is generated inside the event, a new number will be generated with every click.
Thank you I don’t know why I was thinking it is every time the same.
I set this up as described by @Alesso_Bonini but am unsure how to set up the code as recommended by @techleapnz. Can you clarify?
you just need to substitute all random numbers codes with a variable and set a variable to a random number beetween 1 and 3
set it over te code as the first thing the program run
Here you go - remix and compare:
I also removed the click event from the sarcophagus once clicked, so it doesn’t get clicked multiple times.
Hope that helps!
Geoff @ TechLeap
Thank you Geoff! I see where yours works better than mine.