Page 1 of 1

'Case of'?

Posted: Thu Feb 27, 2003 1:46 pm
by Rookie One.pl
Hi,

Is there in MoHAA scripting language a 'case' type command? I mean, a command that does another thing when a variable has another value. In Turbo Pascal there was something like this (here I coloured the code like TP's editor would do):

case variable of
1: writeln("Variable''s value = 1");
2: writeln("Variable''s value = 2");
etc. etc.
end;

I think you know what I mean. I tried to do something with switch, but it gave a strange effect, maybe I did something wrong.

Rookie One

Posted: Thu Feb 27, 2003 2:41 pm
by Innkeeper
The switch stament should be written like this:

Code: Select all

 switch(variable)
{
  case 1: writeln("Variable's value = 1")
          break
  case 2: writeln("Variable's value = 2")
          break
}

Posted: Thu Feb 27, 2003 3:22 pm
by jv_map
writeln really should be println :wink:

You may also use a label instead of a case, to check for a string.
For instance:

Code: Select all

switch(self.position)
{
   stand:
      println "standing :)"
      break
   crouch:
      println "crouching :|"
      break
   pain:
      println "ouch :("
      break
   default:
      println "what the hell am I doing :S"
}
:roll:

Posted: Thu Feb 27, 2003 3:24 pm
by Innkeeper
:oops: you are correct about println. I should have had some coffee first. :?

:)

Posted: Thu Feb 27, 2003 8:50 pm
by Rookie One.pl
Thanks 8) .