Help simplifying a small if-script [Solved]

Anonynn
07 Sept 2019, 22:31Hello! I was just curious if it were possible to shrink this script...
if (calendar.month=1) {
}
else if (calendar.month=2) {
}
else if (calendar.month=12) {
}
else {
}
into something like...
if (calendar.month=1,2,12) {
}
else {
}
or something like that? Any help would be greatly appreciated!
Anonynn.

Io
07 Sept 2019, 23:48Not to my knowledge, but you could use a Switch case.
switch (calender.month){
case(1){
}
case(2){
}
case(3){
}
etc
}

DarkLizerd
08 Sept 2019, 01:49IO... close...
switch (calender.,month){
case(1,2,12){
// do this
}
}
(I think, let me check.)
Yep, it works that way.

Anonynn
08 Sept 2019, 02:13I was trying to avoid doing it via the switch way. But good to know for the future that it definitely can be done like that! Thank you guys so much :D
Anonynn.

Io
08 Sept 2019, 02:45DarkLizerd, doesn't that just result in the cases 1, 2, and 12 all doing the same thing?
Presumably he wants them to do different things; it looks like he's doing a 'if calendar.month=1 set calendar.monthstring to "January" ' type deal.

DarkLizerd
08 Sept 2019, 20:09Io,
Anonynn's example showed if calendar.month=1,2,12...
Also... If can check for multiple conditions on one line...
T=calendar.month
if (T=1 or T=2 or T=12) {
msg ("Hi. T=" + T)
}
Again, this will test T to see if it is 1, 2, or 12...
I like shorter variables... it makes typing so much easer... less chance to mistype a lone name.

Io
08 Sept 2019, 20:44DarkLizerd, it'd perhaps be simpler if we knew precisely what it was he wanted to make. He may very well have assumed calender.onth=1,2,12 would do something other than what it actually does.

DarkLizerd
08 Sept 2019, 21:56Maybe something was to happen only on those months...
OH!!! Winter months!!!
If month=winter
then, there is snow on the ground..
else,
no snow.
mrangel
08 Sept 2019, 22:06You could also do something like:
if (ListContains (Split ("1;2;12"), ""+month)) {
But that's even less efficient.
Really, this is exactly what switch
is made for. I've not actually tested it in Quest, but in most languages switch
is optimised heavily enough that there's a noticeable speed improvement for using it.