Site hosted by Angelfire.com: Build your free website today!

TUTORIALS: RM2k- Switches/Variables




Switches
I) General Information
II) Making a Chest [Difficulty: Beginner]

Variables
III) General Information
IV) Making a Chest 2 [Difficulty: Beginner]
V) Making a Coin Toss Game [Difficulty: Intermediate]

VI) Making a Lottery Game* [Difficulty: Intermediate]
Credits


Please note: Rather than explaining how each thing works, I am giving examples of features that can be included in a game without including the raw code. I hope that these inspire you to experiment and play around with switches and variables.


I. General Information- Switches

-> What is it? <-
A switch is a simple device that can be changed from on to off an unlimited number of times, like a light switch.

-> Why would you use it? <-
You would use a switch to start/stop events in RM2k or practically any other program. For instance, you'd use a switch to prevent the player from gaining items from chests more then once.


II. Making a Chest [Difficulty: Beginner]

{You need 1 switch}

Here I will tell you how to make a chest with an item inside. After obtaining said item, the chest will be empty.
--------------------

  1. Make a new event
    • For the Event Conditions, leave everything blank.
    • For the Graphic, set it to a chest or something.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  2. Double-click on the Event Commands
    • Click on "Add Item..." and have it give you an item.
    • Click on "Show Message..." and make it say "You got an item!" or something.
    • Change a switch to on.

  3. At the top, click on New Page.
    • For the Event Conditions, make it set to switch and select the switch you just turned on.
    • For the Graphic, set it to an open chest.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  4. Double-click on the Event Commands
    • Click on "Show Message..." and make it say "It's empty!"

**You can change the text dialogue to whatever you want.**


III. General Information- Variables

->What is it? <-
A variable is like a switch, but a variable can have multiple settings. If a switch can be compared to a light switch, a variable can be compared to a dimmer switch, being that there are many different possible values.

->Why would you use it? <-
You would use it for the same reason as switches, but variables would be used for events that could have more than two pages and you don't want to waste switches. You can also store specific values in them that can be called later, such as hero statistics, the number of a certain item, or even the number of times that you've talked to a certain character.


IV. Making a Chest 2 [Difficulty: Beginner]

{You need 1 variable}

This chest, although like the one mentioned above, will use only variables and will display different messages each time you try to open the empty chest.
--------------------

  1. Make a new event.
    • For the Event Conditions, leave everything blank.
    • For the Graphic, set it to a chest or something.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  2. Double-click on the Event Commands
    • Have it give you an item.
    • Show message, "You got an item!" or something.
    • Set a variable to one(1).

  3. At the top, click on New Page.
    • For the Event Conditions, make it set to variable and select the variable you just set. Have the number be 1.
    • For the Graphic, set it to an open chest.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  4. Double-click on the Event Commands
    • Click on "Show Message..." and make it say "It's empty!"
    • Make the variable add one.

  5. At the top, click on New Page.
    • For the Event Conditions, make it set to variable and select the variable you just set. Have the number be 2.
    • For the Graphic, set it to an open chest.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  6. Double-click on the Event Commands
    • Click on "Show Message..." and make it say "What did I just say?"
    • Make the variable add one.

  7. At the top, click on New Page.
    • For the Event Conditions, make it set to variable and select the variable you just set. Have the number be 3.
    • For the Graphic, set it to an open chest.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero
    • For the Movement Type, make it stay still.

  8. Double-click on the Event Commands
    • Click on "Show Message..." and make it say "Leave me alone!"
    • Set the variable to one(1).

**You can change the text messages to whatever you want**
**If you want more than 3 responses, repeat steps 3 & 4 untill you have as many as you want. The very last message NEEDS to set the variable to 1 or it doesn't loop the messages.**



V. Making a Coin Toss Game [Difficulty: Intermediate]

{You need 1 variable}

This demonstrates another feature with variables: random number generation. With this mini-game you will have an NPC (Non-Playable Character) who will ask if you want to play. If you answer yes, he'll prompt you for Heads or Tails. Then the variable will randomize and you will either gain or lose something based on the result.
--------------------

  1. Make a new event.
    • For the Event Conditions, leave everything blank.
    • For the Graphic, set it to a person.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero

  2. Double-click on the Event Commands
    • Set a Variable to 0
    • Show a message, "Would you like to play Coin Toss?"
    • Show a choice between "Yes" and "No."
      (The rest is all under the Yes choice)
    • Show a message, "What will it be?"
    • Show a choice between "Heads" and "Tails."
      (Under the Heads choice)
      • Set the variable to random, and in the boxes type 1 and 2.
      • Make a Fork Condition (Check "Variable" and type "1")
        (In the Fork)
        • Show a message, "It's heads!"
        • Give the player money or an item.
        (In the Else case)
        • Show a message, "It's tails!
        • Deduct money or an item from the player.
      (Under the Tails choice)
      • Set the variable to random, and in the boxes type 1 and 2.
      • Make a Fork Condition (Check "Variable" and type "1")
        (In the Fork)
        • Show a message, "It's heads!"
        • Deduct money or an item from the player.
        (In the Else case)
        • Show a message, "It's tails!"
        • Give the player money or an item.

**You can change the text to whatever you want**


VI. Making a Lottery Game* [Difficulty: Intermediate]

{You need 2 variables, 2 switches, 1 common event}

You can purchase a ticket from an NPC, and it takes three minutes to draw a random three-digit number. You can return to the NPC to see if you've won and to collect your prize. The probability that you will guess correctly is 1/1000, so there's no need to deduct money if you lose. NOTE: the \V[####] is the exact number of a variable.
--------------------

  1. Make a new event. (Try putting it somewhere easy to find)
    • For the Event Conditions, leave everything blank.
    • For the Graphic, set it to a person.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero

  2. Double-click on the Event Commands
    • Show message, "Do you want to buy a Lotto ticket for 25 money?
    • Show choice between "Yes" and "No".
      (The rest is all under the Yes choice)
    • Show message, "What do you want your number to be?"
    • Input number (3 digits) and store in variable A.
    • Set variable B to 0.
    • Add an item called Lotto Ticket.
    • Show a message, "I'll let you know if you won in a few minutes."
    • Change Switch A on.

  3. Make a new page.
    • For the Event Conditions, make it for when switch A is on.
    • For the Graphic, set it to a person.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero

  4. Double-click on the Event Commands
    • Show message, "I'll let you know if you won in a few minutes."

  5. Make a new page.
    • For the Event Conditions, make it for when switch B is on.
    • For the Graphic, set it to a person.
    • For the Event Start Conditions, set it to Push Key and Same Level as Hero

  6. Double-click on the Event Commands
    • Make a Fork Condition (Check Variable, select variable A, select variable B in
      the box below, and select same) (In the fork)
      • Show message, "The number is...\| \V[####]. You've won!"
      • Give the player 5000 money.
      • Drop item, Lotto ticket.
      • Change switch B off.
      (In the Else case)
      • Show message, "The number is...\| \V[####]. You lost. Please try again."
      • Drop item, Lotto Ticket.
      • Change switch B off.

  7. Go into the "Common Events" tab of the "Database.
    • For the Start Condition, select Parallel Process.
    • For the Appearance Condition Switch, select switch A.
    • In the Event Commands, wait for 60.0 sec.
    • Wait for 60.0 sec.
    • Wait for 60.0 sec.
    • Set Variable B to random, and in the boxes type 0 and 999.
    • Change Switch B on.
    • -> Change Switch A off.


**You can change the price of the ticket.**
**You can change the prize**
**You can change the text to whatever you want.**
**You can change the amount of time it takes for the results to come in.**


Credits
--------------------
If you wish to use this tutorial on your website, you must link directly from your website to this document (https://www.angelfire.com/rpg2/mastersean2k/switch_variable.html) unless given permission.

Written by MasterSean2k.
mastersean2k@hotmail.com
http://mstuff.s5.com
© 2002 by MasterSgameS

RM2k by ASCII
RM2k translationby Don Miguel