Difference between revisions of "MessageBox Tutorial"
Jump to navigation
Jump to search
→Basics: New section and split things up into sections
imported>Haama m |
imported>Haama (→Basics: New section and split things up into sections) |
||
|
There are two sides to every menu – the display of the menu and catching the player's decision. You display the menu with the function [[MessageBox]] and catch the player's decision with the function [[GetButtonPressed]]. You can keep these two separated by changing a variable (i.e., "Choosing")
===Where to place MessageBox and GetButtonPressed===
[[MessageBox]] takes one frame to display, so you can use any block to display it. However, [[GetButtonPressed]] needs to be in a block that continuously runs (i.e., [[GameMode]], [[MenuMode]], [[ScriptEffectUpdate]]) and needs to be on a script that is running every frame (i.e., an activator that is in a loaded cell, a quest running every .001 seconds, etc.). The reason for this – in order to read it, make a decision, click the option, and let go of the mouse button it will take the player longer than a frame, so you need to run the script every frame until then.
===Keep 'em separated===
The menu will always be displayed first, followed by catching the player's decision. These are distinct parts of the script, so they will have to be kept separate. To do this, use a variable ("Choosing" will be used in this tutorial) and set it to a different number for each part. For instance, for displaying the menu you can use '''''set Choosing to -1''''' to start the menu and '''''if (Choosing == -1)''''' to make sure the menu needs to be displayed. For catching the player's decision, you can use '''''set Choosing to 1''''' and '''''if (Choosing == 1)'''''.
===GetButtonPressed returns numbers from -1 to 9===
Another oddity - [[GetButtonPressed]] returns somewhat odd numbers for each decision:
*'''''-1''''' means no decision has been made
*'''''9''''' for the tenth(you can have 10 options at most)
===(Non-working, but insightful) Example Script for the above concepts===
With those in mind, here's a basic menu script. (You may also notice that it doesn't quite work, that'll be explained afterwards.)
<pre>Short Choosing
End</pre>
The variable "Choosing" is used to separate the display of the menu and the catching of the player's decision. Since it's in a [[GameMode]] block, the script will run every frame. [[GetButtonPressed]] will return '''''-1''''' until the player makes a decision, in which case it will return '''''0''''' or '''''1''''', depending on the player's decision.
==Avoiding Common Mistakes for More Complex Menus==
| |||