Author Topic: (Solved)  (Read 581 times)

So I'm beginning to program things in TorqueScript, and I'm trying to make a serverCmd function.

Code: [Select]
function serverCmdRules(%client, %ruleNum) {
if(!ruleNum) {
messageClient(%client, ' ', "[unimportant message]");
return;
}

switch(%ruleNum) {
case 1:
messageClient(%client, '', "Rule #1");
case 2:
messageClient(%client, '', "Rule #2");
case 3:
messageClient(%client, '', "Rule #3");
// so on . . .
default:
messageClient(%client, '', "[another unimportant message]");
}
}

What I want it to do is when I type '/rules' it will display the unimportant message. When you type '/rules 1' I would want it to skip the unimportant message and display the info about the rule.

So when I type '/rules' that part does as I want, but when I type '/rules 1' it still only displays the unimportant message and doesn't display the info about the rule. When I execute the file, the console says that the 2nd line always defaults to 0, but I'm not sure how to fix this.

All help would be appreciated.
« Last Edit: September 12, 2012, 11:45:09 PM by Katz »

you forgot the %

so ruleNum is being treated as a string and !thatString is true methinks

Wow, how did I not see that. I'm so used to using other languages that don't need the global and local symbols that I guess I screwed myself over. Thanks anyways!

Code: [Select]
function serverCmdRules(%client, %ruleNum)
{
if(!%ruleNum)
{
messageClient(%client, ' ', "[unimportant message]");
return;
}
switch(%ruleNum)
{
case 1:
messageClient(%client, '', "Rule #1");
case 2:
messageClient(%client, '', "Rule #2");
case 3:
messageClient(%client, '', "Rule #3");
default:
messageClient(%client, '', "[another unimportant message]");
}
}
Fixed the syntax