Hi Gunjang,

use of the case command allows you to react to a large number of values
without haviung to write if..then..else if... over and over.

Say for example you had a variable in your movie called 'gAge' and you
wanted to react on different ways depending on it's value. You would use:

on myHandler
 case (gAge) of   -- insert name of thing to be tested here
  34:             -- a value to act upon
   go to frame 1
  22:
   exit
  50:
   set user = 1
  65:
   go the frame
  otherwise:      -- script to perform if none of the above is true
   beep
 end case         -- closing case statement
end

What you test or do is completely up to you. BUT, if you want to do more
than one thing for a value, e.g. set a variable, then call a handler, then
go to a frame etc, the commands must be set out on the line below the value
as above. E.G.

  34:  -- value to act on
   command 1
   command 2
   command 3

Although you don't need to do this when you are only performing one command,
eg

 34: command x
 90: command y
 600: command a

I do it for all statements just to get in the habit.
 You can also perform the same command for a range of values.. eg from some
old game script:

case (sprite(stuff[4]).frame) of
      --going right to mid
    1,2,3,4,5:
      sendsprite(stuff[1], #direct, ((sprite(stuff[4]).frame) - 6), -3)

      --mid
    6,16:
      sendsprite(stuff[1], #direct, 0,-3)

      -- going mid to right edge
    7,8,9,10,11:
      sendsprite(stuff[1], #direct, ((sprite(stuff[4]).frame)-6),-3)

      --going mid to left egde
    17,18,19,20,21:
      sendsprite(stuff[1], #direct, ((-1) - ((sprite(stuff[4]).frame) - 17))
,-3)

      -- going left to mid
    12,13,14,15:
      sendsprite(stuff[1], #direct, (-((sprite(stuff[4]).frame) - 16)),-3)
end case

the same command is applied to the values 1,2,3,4,5 etc without doing them
all on seperate case statements.

Chuck this simpole bit of code into a movie to try it yourself:

on keydown
 case (the key) of
    49:
      put "you pressed the spacebar"
    36:
      put "you pressed return"
    0:
      put "you pressed the a key"
    37:
      put "you pressed the l key"
  end case
end


Leon McComish
Web Developer
email: [EMAIL PROTECTED]

Get the best free games on the web at

www.freeloader.com

freeloader.com is a division of
Pure Entertainment Games PLC
131-151 Great Titchfield Street
London W1P 8AE
tel:     +44 (0)207 663 3900
fax:     +44 (0)207 663 3901



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to