11 March 2010

Chapter 4b: Combination Locks (Advanced) - The Complete Chest Tutorial

Following on from Part 4a, which created a single combination, this tutorial will prevent you from opening the chest unless you know the complete combination beforehand.

For the purposes of this tutorial, we'll create 4 additional events (Bush #1, Bush #2, Bush #3 and Bush #4) that can be searched for each part of the combination. These are dotted around the map so that when "searched", one part of the combination will show up.

We'll also need to create 4 variables (Num 1, Num 2, Num 3 and Num 4) to "store" the individual combination numbers, but this is primarily to avoid using switches when the number is obtained.

The combination for this tutorial will be 4321, with each part stored in the variable "Num Digits". If you attempt to open the chest without first knowing the entire combination of four numbers, you won't be able to open it.

Starting with the Bush #1 event, in the Event Commands, we're going to create a Conditional Branch to determine if the bush has already been searched. If so, display a message with the first number in the combination sequence; if not, set the first number (in this case set to 4) and add one to the number of digits. The complete code will look like this:
<>Branch if Var [0003:Num 1] is 0 Greater
  <>Message: The first number is: \V[3].
  <>
: Else Handler
  <>Variable Oper: [0003:Num 1] Set, 4
  <>Variable Oper: [0007:Num Digits] + , 1
  <>Message: The first number is: \V[3].
  <>
: End

Repeat that with Bush #2, changing "Num 1" to "Num 2", "\V[3]" to "\V[4]" and under the Else Handler change the "4" to a "3", thus:
<>Branch if Var [0004:Num 2] is 0 Greater
  <>Message: The first number is: \V[4].
  <>
: Else Handler
  <>Variable Oper: [0004:Num 2] Set, 3
  <>Variable Oper: [0007:Num Digits] + , 1
  <>Message: The first number is: \V[4].
  <>
: End

Repeat the process for Bush #3 and Bush #4, increasing the values accordingly.

After that, we need to create the chest. For this, we'll check to see if all the numbers needed for the combination lock are known. If not, a message will be displayed telling you that you don't know the full code. If so, check for the correct combination (in this case, 4321) and open the chest upon the correct combination being entered.

We'll be drawing on the previous tutorials - Part 1 (Basic Chests), Part 4a (Combination Locks) and Part 3 (Random Contents) to create the chest.

The complete routine will look like this:
<>Branch if Var [0007:Num Digits] is 4
  <>Input Number: 4 Digit, [0002:Combo]
  <>Branch if Var [0002:Combo] is 4321
    <>Play Sound: open1
    <>Move Event: This Event, Face Right
    <>Wait: 0.2 Sec
    <>Move Event: This Event, Face Up
    <>Wait: 0.2 Sec
    <>Move Event: This Event, Face Left
    <>Wait: 0.2 Sec
    <>Call Event: Random Contents
    <>Switch Operation: [0004:Chest 4b Opened] ON
    <>
  : Else Handler
    <>Message: The combination is incorrect.
    <>
  : End
  <>
: Else Handler
  <>Message: You don't have all the numbers yet.
  <>
: End

Chapter 4a: Combination Locks (Basic) - The Complete Chest Tutorial

Combination locks can be placed on some chests, which will only be opened if the correct combination is entered, otherwise will remain closed. In this two part tutorial, I'll demonstrate how this can be achieved.

The first, which sets up a basic 4-digit combination lock, we need to create another chest event, "Chest 4a". On Page 2, set the Preconditions Switch to "Chest 4a Opened".

On Page 1, we'll set up a variable and input option for the combination (in this case 1234), stored in "Combo", determine if the correct combination has been entered and, if so, provide random contents (detailed in Part 3). If not, the chest remains closed.

The complete code on Page 1 will look like this:
<>Input Number: 4 Digit, [0002:Combo]
<>Branch if Var [0002:Combo] is 1234
  <>Play Sound: open1
  <>Move Event: This Event, Face Right
  <>Wait: 0.2 Sec
  <>Move Event: This Event, Face Up
  <>Wait: 0.2 Sec
  <>Move Event: This Event, Face Left
  <>Wait: 0.2 Sec
  <>Call Event: Random Contents
  <>Switch Operation: [0001: Chest 4a Opened] ON
  <>
: Else Handler
  <>Message: The combination is incorrect.
  <>
: End

When you playtest the game, if you try and open the chest with any other combination than 1234, the combination will be incorrect. Trying 1234 will open the chest and give random items (from Part 3).
Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner