How do I Compare A Variable to a Range of Numbers

Get help using Construct 2

Post » Wed Dec 17, 2014 6:25 pm

Example:

Code: Select all
var "a" = 32 or 37 or 38 or 39 or 40{
Do something()
}


So if a variable is equal to one of those numbers, something happens.

EDIT: I'm looking for one line solution, not making "or" or adding more conditions.
Last edited by Android-Music on Wed Dec 17, 2014 7:08 pm, edited 1 time in total.
B
80
S
23
G
6
Posts: 240
Reputation: 7,761

Post » Wed Dec 17, 2014 6:32 pm

Right-click the event and choose "Make 'Or' Block", then add all conditions that apply.

or-block.png
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 624
Reputation: 3,750

Post » Wed Dec 17, 2014 7:06 pm

Nah, sorry, that's not what am I looking for, one line solution is the aim.
B
80
S
23
G
6
Posts: 240
Reputation: 7,761

Post » Wed Dec 17, 2014 7:13 pm

Use "Compare two vales", a=32 | a=37 "Equal to" 1
ImageImageImage
B
71
S
22
G
248
Posts: 3,757
Reputation: 138,065

Post » Wed Dec 17, 2014 7:22 pm

Not gonna happen.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 624
Reputation: 3,750

Post » Wed Dec 17, 2014 7:30 pm

@blackhornet , that's quite an interesting solution, will try that for sure, thanks a lot! :)

EDIT: wow it really works, thanks again!
B
80
S
23
G
6
Posts: 240
Reputation: 7,761

Post » Wed Dec 17, 2014 8:17 pm

If you want to be clever you could do this too:
find(",32,37,38,39,40,", ","&a&",") >=0

Or you could make a function if you plan on doing something like that more than once:

on function "one of em"
for "" from 1 to Function.ParamCount-1
function: parameter 0 = Function.Param(loopindex)
--- set return to 1


Then you can use it with:
System: compare Function.call("one of em", a, 32, 37, 38, 39, 40) = 1
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Wed Dec 17, 2014 8:24 pm

Nice solution R0J0hound! O.o
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 624
Reputation: 3,750

Post » Wed Dec 17, 2014 8:33 pm

Thanks @R0J0hound , this solution is great too!
B
80
S
23
G
6
Posts: 240
Reputation: 7,761


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests