torquescript switch statements - maximum of 83 case statements ?
by Orion Elenzil · in Torque Game Engine · 04/06/2009 (3:07 pm) · 6 replies
torquescript (TGE 1.3.5) seems to generate a syntax error on the 84th case statement in a switch statement.
anyone know how to change this limit ?
tia,
orion
fwiw, here's an 83-case switch:
anyone know how to change this limit ?
tia,
orion
fwiw, here's an 83-case switch:
function testSwitch(%foo) {
switch$(%foo) {
case "string1":
echo("string1");
case "string2":
echo("string2");
case "string3":
echo("string3");
case "string4":
echo("string4");
case "string5":
echo("string5");
case "string6":
echo("string6");
case "string7":
echo("string7");
case "string8":
echo("string8");
case "string9":
echo("string9");
case "string10":
echo("string10");
case "string11":
echo("string11");
case "string12":
echo("string12");
case "string13":
echo("string13");
case "string14":
echo("string14");
case "string15":
echo("string15");
case "string16":
echo("string16");
case "string17":
echo("string17");
case "string18":
echo("string18");
case "string19":
echo("string19");
case "string20":
echo("string20");
case "string21":
echo("string21");
case "string22":
echo("string22");
case "string23":
echo("string23");
case "string24":
echo("string24");
case "string25":
echo("string25");
case "string26":
echo("string26");
case "string27":
echo("string27");
case "string28":
echo("string28");
case "string29":
echo("string29");
case "string30":
echo("string30");
case "string31":
echo("string31");
case "string32":
echo("string32");
case "string33":
echo("string33");
case "string34":
echo("string34");
case "string35":
echo("string35");
case "string36":
echo("string36");
case "string37":
echo("string37");
case "string38":
echo("string38");
case "string39":
echo("string39");
case "string40":
echo("string40");
case "string41":
echo("string41");
case "string42":
echo("string42");
case "string43":
echo("string43");
case "string44":
echo("string44");
case "string45":
echo("string45");
case "string46":
echo("string46");
case "string47":
echo("string47");
case "string48":
echo("string48");
case "string49":
echo("string49");
case "string50":
echo("string50");
case "string51":
echo("string51");
case "string52":
echo("string52");
case "string53":
echo("string53");
case "string54":
echo("string54");
case "string55":
echo("string55");
case "string56":
echo("string56");
case "string57":
echo("string57");
case "string58":
echo("string58");
case "string59":
echo("string59");
case "string60":
echo("string60");
case "string61":
echo("string61");
case "string62":
echo("string62");
case "string63":
echo("string63");
case "string64":
echo("string64");
case "string65":
echo("string65");
case "string66":
echo("string66");
case "string67":
echo("string67");
case "string68":
echo("string68");
case "string69":
echo("string69");
case "string70":
echo("string70");
case "string71":
echo("string71");
case "string72":
echo("string72");
case "string73":
echo("string73");
case "string74":
echo("string74");
case "string75":
echo("string75");
case "string76":
echo("string76");
case "string77":
echo("string77");
case "string78":
echo("string78");
case "string79":
echo("string79");
case "string80":
echo("string80");
case "string81":
echo("string81");
case "string82":
echo("string82");
case "string83":
echo("string83");
// case "string84": // syntax error
// echo("string84");
}
}About the author
#2
04/07/2009 (12:05 am)
Is it really efficient to have a switch with that many cases? But I guess the principle is that you should be able to have as many as you want.
#4
Doesn't seem to be a problem in TGE 1.5.2 (or TGEa 1.8.1) -- so apparently it was fixed. I was curious and bumped your testswitch() up to 200 cases, maybe sometime if I get bored I'll push it further. But still, surely you wouldn't need that many!
EDIT: you might be able to get someone with 1.3.5 to compare with 1.5.2 and possibly trace the fix down for you.
04/08/2009 (10:18 pm)
Whoa, how on earth did you find that out?Doesn't seem to be a problem in TGE 1.5.2 (or TGEa 1.8.1) -- so apparently it was fixed. I was curious and bumped your testswitch() up to 200 cases, maybe sometime if I get bored I'll push it further. But still, surely you wouldn't need that many!
EDIT: you might be able to get someone with 1.3.5 to compare with 1.5.2 and possibly trace the fix down for you.
#5
04/08/2009 (10:39 pm)
Let the record reflect that Orion is the master of finding weird sh*t in TorqueScript that some of us have either forgotten or did not even know about.
#6
finally some traction on this extremely pressing issue!
as background, this is the switch statement that handles the various options in the menu you get when you right-click on an avatar in our app. apparently we now have that many different actions that can be taken. hard to believe. but it covers clicking on other people's avatars, clicking on your own avatar, options that only appear for site moderators, and a bunch that are just esoteric debugging stuff. hm, even so it's hard to believe - i would expect more like thirty.
tim - hah, yeah, it's totally ugly. i don't actually mind an 80+ case switch statement for something executed so rarely, but breaking it up into multiple switches is .. grody, i think would would be the word. a table would be much better.
michael - huh, interesting. i have to admit i didn't try the huge switch with a stock engine; it may be something we broke. i'll try it with stock TGE 1.4.
michael - lol, thanks for setting the record straight !
04/09/2009 (12:39 am)
lol!finally some traction on this extremely pressing issue!
as background, this is the switch statement that handles the various options in the menu you get when you right-click on an avatar in our app. apparently we now have that many different actions that can be taken. hard to believe. but it covers clicking on other people's avatars, clicking on your own avatar, options that only appear for site moderators, and a bunch that are just esoteric debugging stuff. hm, even so it's hard to believe - i would expect more like thirty.
tim - hah, yeah, it's totally ugly. i don't actually mind an 80+ case switch statement for something executed so rarely, but breaking it up into multiple switches is .. grody, i think would would be the word. a table would be much better.
michael - huh, interesting. i have to admit i didn't try the huge switch with a stock engine; it may be something we broke. i'll try it with stock TGE 1.4.
michael - lol, thanks for setting the record straight !
Associate Orion Elenzil
Real Life Plus
%handled = false; if (!%handled) // split into several switch()es because of 83-case limit. http://www.garagegames.com/community/forums/viewthread/88687 { %handled = true; switch$(%value) { case "foo": doStuff(); default: %handled = false; } } if (!%handled) // split into several switch()es because of 83-case limit. http://www.garagegames.com/community/forums/viewthread/88687 { %handled = true; switch$(%value) { case "bar": doStuff(); default: %handled = false; } }