Gw Temp

Menu

Tutorial - 'Using Labels and the Goto command' by CyTWO

An item about RPGMaker 2000 posted on

Blurb

This Tutorial teaches you how to eliminate use of loops and cycles, as well as making definable loops, by using the label and goto commands.

Body

Basic and advanced use of Labelling and the Goto command in rm2k
~By CyTWO~

No funny comments for you sir! Let’s jump straight into it, shall we?
The label and goto commands are mainstays of both “real” programming and advanced
use of the rm2k scripting. Not only does it allow you to make definable loops, it also
totally negates the need for any ‘cycles’ in your program.
First, the basics: Use of the label and goto command.
Imagine you have want a particular part of a program to repeat. Rather then using a loop,
which makes for messy looking and confusing code, you would put a label command
directly in front of the code you wish to repeat, and then, further down in the code, you
would insert the goto command. That way, once RM2k reaches the goto, it immediately
skips back to the label.
For example, say you wanted to display some choices, and allow the choices to be
shown again after one choice had been selected and run through. By using the label and
goto command, you would be able to display the choices again even after one of the
choice has been selected without requiring the user to “talk” to the person a seperate
time.
Example code:

>Messg: “Hello, would you like directions?”
>Label 1
>Show choice : “Arena”, “Barroom”, “Bathroom”, “Never mind”
> “Arena”
>Messg: “Go left at the big fork in the road.”
>Goto Label 1
>”Barroom”
>Messg: “Go Right at the big fork in the road.”
>Goto Label 1
>”Bathroom”
>Messg: “Go at the big fork. I’m sure no one will mind.”
>Goto Label 1
>”Never Mind”

Leave the last option blank so that the event will end and the user can continue on.

Now, you can see how useful the label and goto command are, but how does it do
anything that the cycle or loop commands can’t? Well, that’s the next bit.
Because the goto command is a single “leap” command, it doesn’t need to have
all the text contained in it, so it can easily be used with the fork condition command,
unlike the loop or cycle commands. Just label a certain area of your code, then use a fork
condition to determine whether the conditions you want are met, and if so (or not) then
use the goto command to leap back up to the portion of code you want reperformed.


Example code:
>show picture 1 by picture x and picture y
>Label 1
>Fork condition (If variable picture x = 300 then/else)
>Then
>Erase Picture
>Else
>Variable picture x + 1
>Move picture 1 by picture x/picture y
>Goto Label 1


See? And that would continue to check the value of a variable, picture x; when it reached
300, it would erase the picture; until then, it would continue to add 1 to the picture x,
making it seem as though it were scrolling across the screen.

There you go! The label and goto commands are among the most versatile, with many
uses. This tutorial hopefully gave you a basic understanding. Have fun!