Torquescript tip: duplicate case statements
by Orion Elenzil · in Torque Game Engine · 07/02/2008 (9:57 am) · 8 replies
In C, you can go like this:
.. and case A and B both doStuff().
but in torqueScript, there are no break statements;
it uses the next case statement as the break,
which means that case A would do nothing, while case B would doStuff().
passing through EditorGui::getHelpPage(),
i just learned the torquescript equivelant:
crazy !
switch()
{
case A:
case B:
doStuff();
break;
case C:
doOtherStuff();
break;
}.. and case A and B both doStuff().
but in torqueScript, there are no break statements;
it uses the next case statement as the break,
which means that case A would do nothing, while case B would doStuff().
passing through EditorGui::getHelpPage(),
i just learned the torquescript equivelant:
switch()
{
case A or B:
doStuff();
case C:
doOtherStuff();
}crazy !
About the author
#2
here's some working code.
07/02/2008 (10:34 am)
Nope, it's literally "or" !here's some working code.
function foo()
{
for (%n = 1; %n <= 3; %n++)
{
switch (%n)
{
case 1 or 2:
echo(%n SPC "is one or two!");
case 3:
echo(%n SPC "is three");
}
}
}which yields[7/2/2008 10:34:05][Inf][General] ==>foo(); [7/2/2008 10:34:05][Inf][General] 1 is one or two! [7/2/2008 10:34:05][Inf][General] 2 is one or two! [7/2/2008 10:34:05][Inf][General] 3 is three
#3
I need to go back and read through my own docs....that's crazy. Fantastic syntax find!
07/02/2008 (10:36 am)
O_oI need to go back and read through my own docs....that's crazy. Fantastic syntax find!
#4
07/02/2008 (11:05 am)
It looks like it only applies to switch statements. I tried to use 'or' in an if statement to see if it could be used as an operator in general. I got a syntax error.
#5
07/02/2008 (11:05 am)
Excellent
#6
[goes to rewrite his case statements]
07/02/2008 (12:06 pm)
Very handy actually, isn't this the way penicillin was invented?[goes to rewrite his case statements]
#7
07/02/2008 (12:11 pm)
@Dave - Actually, penicillin was discovered by John Rhys-Davies when he "slid" into a parallel universe.
Employee Michael Perry
ZombieShortbus
switch() { case A [i]||[/i] B: doStuff(); case C: doOtherStuff(); }I know it's pseudo code, just want to make sure there is no "or" syntax I've never heard of =)