Difference between revisions of "MessageBox Tutorial"
Jump to navigation
Jump to search
→Basics: Rewrite
imported>Haama (→Intro: Rewrite) |
imported>Haama (→Basics: Rewrite) |
||
|
Most MessageBox mistakes stem from adapting a script that works in some cases, but not in more complex situations. To prevent this, this tutorial will show you how to make an all-purpose script that can be used and expanded for any situation. We'll start out with some of the basic mechanics of the MessageBox and related functions, followed by common mistakes in complex scripts, and then the all-purpose script and how to set it up. Finally, we'll go through how to use the script to easily move between multi-layered menus, and some extras that you can tack on to it.
==Basic Mechanics of MessageBox and Related Functions==
Every menu requires two functions: [[MessageBox]] to display the menu, and [[GetButtonPressed]] to return which button the player pressed. Follow the links for more details, but here are the important things to remember:
#GetButtonPressed returns numbers from –1 to 9:
*'''''-1''''' means no decision has been made▼
*'''''0''''' means the player selected the first option▼
*'''''1''''' for the second▼
*...▼
*'''''9''''' for the tenth(you can have 10 options at most)▼
#GetButtonPressed will only return the correct button press the first time it's called in a script; any other use of GetButtonPressed will return -1. For instance, if the player presses the first button, then in the following script
<pre>if (GetButtonPressed == -1)
...
elseif (GetButtonPressed == 0)</pre>
GetButtonPressed will return 0 the first time, move on to the 'elseif' test, and return –1 the second time.
To take care of this, set a variable to GetButtonPressed, and test the variable instead, as such:
<pre>short Choice
...
set Choice to GetButtonPressed
if (Choice == -1)
...
elseif (Choice == 0)</pre>
===Where to place MessageBox and GetButtonPressed===
===Keep 'em separated===
Putting it all together, so far we end up with a script like this:
<pre>short Choice
...
messagebox "Your menu" "Button 0" ... "Button 9"
set Choice to GetButtonPressed
if (Choice == -1)
...
elseif (Choice == 0)
...</pre>
The problem with this script – every time it repeats while waiting for GetButtonPressed to return the player's button press, the MessageBox will be displayed again. To prevent this, you need to use a variable to keep them separated, as such:
<pre>short Choosing
short Choice
...
if (Choosing == -1)
messagebox "Your menu" "Button 0" ... "Button 9"
set Choosing to 1
set Choice to GetButtonPressed
elseif (Choosing == 1)
set Choice to GetButtonPressed
if (Choice == -1)
...
elseif (Choice == 0)
...</pre>
Note that both halves are required for each menu. To help keep things organized, you can set one to a negative number, and the other to a positive number, as in the above script.
▲===GetButtonPressed returns numbers from -1 to 9===
▲*'''''-1''''' means no decision has been made
▲*'''''0''''' means the player selected the first option
▲*'''''1''''' for the second
▲*...
▲*'''''9''''' for the tenth(you can have 10 options at most)
===(Non-working, but insightful) Example Script for the above concepts===
| |||