Is there a simpler way to check if a variable = a series of specific numbers?

D

Darren

Guest
I'm adding (imaginary) times and dates to my game and need to say "if month number = 12, or 1, or 2, season = Winter"

I've tried || and or and neither work, do I really have to write my code like

if monthno = 12 season = "Winter";
if monthno = 1 season = "Winter";
if monthno = 2 season = "Winter";

there must be an easier way I can't find in the manual I'm sure! Like a way of going if monthno = 12,1,2 season = "Winter"

Any help appreciated! And this isn't asking for a range by the way, I need specific numbers. (I know if monthno >= 12 && monthno <= 3 would work, but for futureproofing I want to find how to call specific numbers so I could say month 3,7,9 = do this.
 

Tsa05

Member
Code:
if ( monthno == 12 or monthno == 1 or monthno ==2 ){
     season = "Winter";
}
I also wrote a little script you could use over at gmlscripts:
https://www.gmlscripts.com/forums/viewtopic.php?id=2287

If you put that into a script named is_in, then you could do this:
Code:
if( is_in(monthno, [12,1,2] ){
     season = "winter";
}else if( is_in(monthno, [3,7,9] ){
     season = "Weird Season";
}
 
D

Darren

Guest
Code:
if ( monthno == 12 or monthno == 1 or monthno ==2 ){
     season = "Winter";
}
I also wrote a little script you could use over at gmlscripts:
https://www.gmlscripts.com/forums/viewtopic.php?id=2287

If you put that into a script named is_in, then you could do this:
Code:
if( is_in(monthno, [12,1,2] ){
     season = "winter";
}else if( is_in(monthno, [3,7,9] ){
     season = "Weird Season";
}
That's really helpful, I'll be using that script I like everything looking clean, thank-you!
 
Top