Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How to use Variables and Switches

I know there is a thread somewhere but does anyone have the link that will explain what variable are and how to use them?

Help would be greatly appreciated!
:)

-Drifter
 
Variable are like math fuction e.g. <insert name of variable here> and it's <value>. It uses as in event. Just create an event and select "Control Variable" a variable can be displayed or change event switch. for Switch is like on and off button ;) also there's is a self switch


To use a variable: Simply create an event and new event page click preconditon variable and put variable name and number below.. It can also show's player HP or money etc
 
Jrr Kein;332057 said:
Variable are like math fuction e.g. <insert name of variable here> and it's <value>. It uses as in event. Just create an event and select "Control Variable" a variable can be displayed or change event switch. for Switch is like on and off button ;) also there's is a self switch

Some of that made sense and some of it didn't.

':|

What I understand is this.

Understand:

You're saying that Variables basically call out something in an event? What does that entail? Like... what are variables good for doing? I need an example. I'm a noob at Vars, and Switches.

Don't Understand:
Switches are pretty iffy for me also. I would like to know what they're good for doing with specific examples. Because I do know that a good Rpg NEEDS to be made up of Variables and Switches, otherwise it will just be the biggest pain in the world without them.

More help please?

-Drifter
 
Variable are good for events and displaying some properies like amount of money/Player's HP.

Switch is the same as a variable for making an event :s.. Your to RPG making :D
 
Well if you've done algebra you should know what a varible is. A value...in RMXP there is no predetermined value of the value though. You have to set the value yourself and you can use that value for a fishing event for example.Let me give you quick walkthrough-
Say you want to make a event where it shows the player's level. Well to do that make a varible and under the options and check actor and select level. What you have just done is made that varible hold the value of the actor's level. Then in a message say "You level is \v[(put the varible you used here]. Do you undestand Varibles?

Now for switches >.>
A switch is like a light switch. If you flip it up something happens. Its the same for rmxp. Say you want to make a person appear out of nowhere after you talk to bob. Well at the end to bob's conversation put a switch on. Then make a new event and make the first page blank and make a new page. On the new page set the conditions on the left to "Switch001 on". So now you should have a good swith event...
 

Zeriab

Sponsor

In regards to eventing:

You can consider a variable as a container for a number. A variable can contain any number between -99 999 999 and 99 999 999, both inclusive. The default number in all variables is 0.
Here is a tutorial on variables: RMXP Switches & Local Switches Demystified - by Dubealex

Similar can you consider a switch as a container for a light bulb. Either the light bulb is turned ON or turned OFF. By default all light bulbs are turned OFF
Here is a tutorial on switches: RMXP Variables Demystified - by Dubealex

In regards to the scripting:
In a practical perspective you could consider all objects to have nil as default value. Conceptually you shouldn't consider nil as an value, but never mind that.
A game switch is a variable which is assumed to be either true or false
A game variable is a variable which is assumed to be an integer.

Game switches and variables as created with a technique known as lazy instantiation (or lazy initialization).
This basically means they are created when needed and only then given their default values.
 
Make 2 pages.
First page
-your code here-
@>Switch operation: [0001] ON

Second page.
Just set the trigger (on the top- left corner, below the event name thing...) to switch 0001

Did you understand how it works. After your whole code it turns on a SWITCH which does something like marks that this piece of code is over. On the second page, you set the trigger as the switch you just turned on. So that means that the code has been executed and the switch has been turned on. The second page checks to see whether the switch is ON or not. And after the code it is turned on. On the second page, there is no code. If you put code over there, that code will be executed after the switch is turned ON.

Example: If you want some person to block your way, and only move after you have talked to somebody else, then you'll use a switch. You will make the person blocking your way have to pages. On the first page, you will make a message saying "I can't let you pass" (or anything you want) . On the second page, you will remove his graphic, and also make his type "Through". But, on the second page, you will set the trigger to the switch that will be turned ON after you speak to the person who he wants you to speak to. The other person's code will be like this:

@>Show message: Now that stupid old man will let you pass
@>Switch operation: [0002: Spoken to person] ON

And the second page trigger will be switch: [0001: Spoken to person]

This checks, whether you have spoken to the person or not. And if you have, then the switch will also be on, resulting in the <<man blocking your way>> 's graphic as well as the position changing.

Note: On the second page, make sure you change the graphic to nothing and the type to "Through"

PS: You might want to name your switches, just like I have named switch 0002 "spoken to person" . This doesn't have an effect on the game, but it is used for reference so that you can remember what each switch does.

Self Switches: Self Switches are similar to switches, except, when you're using a self-switch, it works only on the event you turn it ON. In the previous example, you saw that you had to talk to two people for the whole process to end. That is why a switch is used. The value of switches, are taken into consideration by every event, whereas a self-switch is one which is INDIVIDUALLY meant for the specific event.

Example: A chest.

Page 1:
@>: Text: You got a potion!!
@>: Change items: Potion + 1
@>: Self Switch A: ON

Page 2: [trigger: Self Switch A]
@> Text: It's empty.


You see? Now this self-switch will ONLY work on this specific chest, and not on any other event.


PS: Very very tired, typing such a detailed description. I'll explain variables later... but you can expect a detailed explanation from me  ;)
 
Hurray! Thank you guys. This all makes a bunch more sense. And sorry about the long response, i've been busy with the family.

I will take a look into those links and start study'in!

;D
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top