'Case of'?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

'Case of'?

Post 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
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Innkeeper
Colonel
Posts: 475
Joined: Mon Nov 25, 2002 10:13 pm
Location: NC, USA (about 7.5 klicks from the capital dome)
Contact:

Post 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
}
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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:
Image
Innkeeper
Colonel
Posts: 475
Joined: Mon Nov 25, 2002 10:13 pm
Location: NC, USA (about 7.5 klicks from the capital dome)
Contact:

Post by Innkeeper »

:oops: you are correct about println. I should have had some coffee first. :?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

:)

Post by Rookie One.pl »

Thanks 8) .
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply