Random number exclusion

Get help using Construct 2

Post » Thu Apr 11, 2013 11:45 pm

This is a real beginner's question, I think...

How do I exclude a number from being randomly generated? Essentially, I want to save the last number generated as a variable then exclude it from the next pick so the same number is never picked twice in a row.
B
5
S
1
Posts: 52
Reputation: 640

Post » Fri Apr 12, 2013 4:40 am

You can make a global variable called "Last_generated_number" and each time you generate a number you store it here.

Then you can do a check:

While
random(number) = Last_generated_number

Then as long the random(number) = Last_generated_number it will make a new roll.

Then when its not Equal to the "last_generated_number" it will continue and you can use it. Then you store the new number in the "last_generated_number" variable, so it will be used for the check next time.

If you dont used negative numbers. You can just put "Last_generated_number" to -1 as default from the beginning, so it will never match the first generated number.



nimos1002013-04-12 04:42:43
B
40
S
10
G
2
Posts: 1,148
Reputation: 6,495

Post » Fri Apr 12, 2013 12:00 pm

I have made this with an array and choose.

Array: 0:"0", 1:"1", 2:"2"

than choose on the indexes and delete the picked one.
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Fri Apr 12, 2013 1:19 pm

Thank you both! That's exactly what I needed to know.
B
5
S
1
Posts: 52
Reputation: 640


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests