0 Favourites

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

• 3 posts
• 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!

• 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.

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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:

It's a really useful plugin and I'm using it a lot in my game.

• 3 posts