How do I Compare two random values as 'either'?

Get help using Construct 2

Post » Wed Oct 11, 2017 1:53 am

How can I ask the code if the numbers it returned with 'random(100)' are 'either(1, 2, 3, 4 or 5)'?

Here is what I want:

System - Random(100) Equal to | either(1, 2, 3, 4, or 5)

I understand there's no 'either' expression but that's what I'm asking. What expression is used in place of 'either' to get the result I want? And if there isn't one, how can I write my code to get the desired result? My brain is fried trying to figure this out!
B
25
S
10
G
1
Posts: 154
Reputation: 2,687

Post » Wed Oct 11, 2017 2:10 am

Store the random result to a local variable (local=int(random(100)), and use it to test the result. If the values are actually 1 to 5, just add two conditions for local >= 1 AND local <= 5. Other wise you need to check each value , but in an OR block instead of an AND block.
ImageImageImage
B
71
S
22
G
248
Posts: 3,759
Reputation: 138,069

Post » Wed Oct 11, 2017 2:21 am

To add to the previous comment.

If numbers are sequential as in your example, you can use "System -> Is between values -> floor(random(100)) between 1 and 5"

There are also a few workarounds to optimize it. For example, you can do this:
Compare two values-> find ("#1#2#3#9#15#" , "#" & floor(random(100)) & "#") >= 0

Or install the SwitchCase plugin:
viewtopic.php?t=64458&start=0
It's a really useful plugin and I'm using it a lot in my game.
Check out my awesome game Doptrix
B
17
S
9
G
50
Posts: 829
Reputation: 27,967


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests