Creating a door


If objects have different states you must check the current state before you know what to do. For example a door which can be open and closed. State 1 is closed and state 2 is open. The first part of the script looks like this :

on (mouse)
 {
 if_obj (door ; 1)
   showinfo (Door ; true)
 if_obj (door ; 2)
   showinfo (Exit ; true)
 }

on (click)
 {
 if_obj (door ; 1)
   walkto (self ; x1 ; y1)
 if_obj (door ; 2)
   walkto (self ; x2; y2)
 }

x1,y1,x2 and y2 are two coordinates on the walkmap, one for door closed and one for door open.
It depends on the state of the door if the character walks to point 1 or point 2. When an object changes its state it maybe neccessary to edit the walkmap. In this case the coordinate for an open door is blocked when the game starts and will be set to free when the player opens the door.

on (open)
 {
 if_obj (door ; 2)
   break ()

 setobj (door ; 2)
 pickup (self)
 setwalkmap (yourroom ; x2 ; y2 ; true)
 }

The first part checks if the door was already opened and will stop the script in this case with the command break ().
If the door is closed the state of the door will be changed, the character performs his/her pickup-animation and the walkmappoint for exiting the room will be set to free.