A question about "switch$" and normal switch statements. [Solved]

Author Topic: A question about "switch$" and normal switch statements. [Solved]  (Read 1091 times)

This is gonna seem noob as hell. And most of the links in the sticky seem unhelpful on this specific issue.

More to the point, searching "switch$" seems to get me more addons about switches than info on switch statements.

My basic question is this.

I've been looking through addon code, modifying, trying to learn whats what through both reading up on info, and modifying and testing.

From my understanding, or a guess this has to do with casting the value to a string.

But it's a switch statement.

What is the difference between switch$() and switch() statements?
« Last Edit: November 07, 2020, 11:37:18 PM by Master Matthew² »

http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Simple/Switch.html

Syntax Review

There are two types of switch statements used in TorqueScript. switch(...) is used to compare numerical values and switch$(...) is used to compare strings.


Standard switch statements use numerical values to determine which case to execute:


Quote
switch Syntax:

switch(<numeric expression>)
{
   case value0:
       statements;
   case value1:
       statements;
   case value3:
       statements;
   default:
       statements;
}

Switch statements requiring string comparison use the switch$ syntax.


switch$ Syntax:

switch$ (<string expression>)
{
   case "string value 0":
                statements;
   case "string value 1":
                statements;
...
   case "string value N":
                statements;
   default:
                statements;
}

http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Simple/Switch.html

Syntax Review

There are two types of switch statements used in TorqueScript. switch(...) is used to compare numerical values and switch$(...) is used to compare strings.


Standard switch statements use numerical values to determine which case to execute:
Thanks, I also seem to have missed that link.