Step 9 : (How to use the lock)

Create a new room and name it "Safe". For the background use the image "safelock". Create also a new object with the name "Number". There are ten images containing numbers from 1-0. Use one for each state of the object. (State 10 is the number "0" then).

Put the new object into the room and place it into the gap of the lock.
The number shall increase now when the player clicks on the lock. For that we need an area to be able to click on. Create a new dummy object with a size of 180x180 and place it right over the lock.

For the next part you need to know about number variables in the game. These are numbers that can be queried, added or subtracted and they highly increase our possibilities. Number variables will NOT be predefined in the editor (like booleans), so we have to reset them in the game.
By entering the room "safe" we will reset a number now.
Add to the roomscript of "safe" :

  on (enter)
  {
    setnum (locknumber ; 1)
  }

We have now declared a number called "locknumber" and set it to "1". Click now on the dummyobject and use this script for it :

  on (mouse)
    showinfo (Lock ; true)

  on (click)
    {
    if_num (locknumber ; <11)
      setnum (locknumber ; +1)
    if_num (locknumber ; 11)
      setnum (locknumber ; 1)

    setobj (number ; [locknumber] )
    playsound (click)
    }

The instruction "if_num" verifies a number variable and it can be used with operators like "<" and ">". The "setnum" instruction can be used with "+" or "-" to add or subtract a value.
Our number will now be increased up to "11" and then put back to "1".
The "setobj" instruction is used this time with our number variable. The square brackets are used to tell the game that this is a variable and not a value.

Square brackets can be used with "setnum" or "if_num", too!!


Step 10 : (How to enter the combination)

The combination for the safe has 3 numbers : 7, 5, and 9. Create another dummyobject (100x50) and place it over the button with "push" on it.
The button shall only be triggered 3 times so we have to remember how many times the player clicks on it. Add this to the "on (enter)" event of the roomscript :

  setnum (pushcount ; 0)

When the room is entered "pushcount" will be set to "0". Now modify the script for the new dummy object :

  on (mouse)
    showinfo (Enter ; true)

  on (click)
    {
    setnum (pushcount ; +1)

    if_num (pushcount ; 1)
      setnum (code1 ; [locknumber] )
    if_num (pushcount ; 2)
      setnum (code2 ; [locknumber] )
    if_num (pushcount ; 3)
      {
      setnum (code3 ; [locknumber] )
      setfocus (last)
      cutscene (result)
      }

    playsound (click)
    }

"pushcount" will be increased by 1 every time the player hits the button. Depending on how many times the player has pushed the button either "code1", "code2" or "code3" will be set to the current position of the lock.
After the third push the instruction "setfocus(last)" sets the focus back to Horst and a cutscene named "result" will be started.
If you have turned of the taskbar before, you have to turn it back on with "taskbar (true)".

Next