Difference between revisions of "MessageBox Tutorial"
no edit summary
imported>Haama (→Extras: Centralizing Menu Exits no longer needed) |
imported>Darkness X |
||
(12 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]|opt0=[[OBSE]]}} | |||
==Intro== | ==Intro== | ||
Most MessageBox mistakes | Most MessageBox mistakes are made when simple scripts are used as a base for more complex menu scripts. To prevent this, this tutorial will work towards a single all-purpose script that can be used and expanded for any situation. By the end, you will know the problems that can pop-up in a menu script, how to prevent them, and why every line of the all-purpose script is needed. | ||
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. | |||
Note that there are 4 mediums to attach a menu script to: Activators, Quests, Tokens (Object scripts on items in the player's possession), and Spells (or Magic Effect scripts). This article will focus mainly on activators, but the other methods, their differences, and how to set them up will be discussed on other pages. Activators are the focus as they are easier and safer to use in most situations (see [[MessageBox_Tutorial#In_which_I_try_to_convince_you_to_use_an_activator|"In which I try to convince you to use an activator"]] for the reasons, though it's highly suggested to read the article first). | |||
==Basic Mechanics of MessageBox and Related Functions== | ==Basic Mechanics of MessageBox and Related Functions== | ||
Line 182: | Line 177: | ||
endif | endif | ||
end</pre> | end</pre> | ||
Note that each menu has a pair of corresponding numbers: Main menu, -1/1; Armor menu, -10/10; Weapon menu, -11/11. When you set Choosing to the corresponding number, that menu will be shown. You can find more information in the [[MessageBox Tutorial#Moving Between Multiple Menus]] section. | Note that each menu has a pair of corresponding numbers: Main menu, -1/1; Armor menu, -10/10; Weapon menu, -11/11. When you set Choosing to the corresponding number, that menu will be shown. You can find more information in the [[MessageBox Tutorial#Moving Between Multiple Menus|Moving Between Multiple Menus]] section. | ||
===Running the same choice for multiple frames=== | ===Running the same choice for multiple frames=== | ||
Line 278: | Line 273: | ||
end</pre> | end</pre> | ||
Set Working to 0 when you wish to keep the script from running. | Set Working to 0 when you wish to keep the script from running. | ||
* These solutions work hand in hand. When the script should be running, and Working is 1, set Working to 1 at the | * These solutions work hand in hand. When the script should be running, and Working is 1, set Working to 1 at the beginning of every frame to keep it loaded for the next frame. When it's 0, don't set any variables and the activator will be unloaded, preventing the script from errantly running. Combining them looks like this: | ||
<pre>short Working | <pre>short Working | ||
... | ... | ||
begin | begin onActivate | ||
... | ... | ||
set Working to 1 | set Working to 1 | ||
Line 288: | Line 283: | ||
begin GameMode | begin GameMode | ||
if Working | if Working | ||
set Working to 1 | |||
if (Choosing == 0) | if (Choosing == 0) | ||
set Working to 0 | set Working to 0 | ||
Line 294: | Line 291: | ||
... | ... | ||
endif | endif | ||
endif | endif | ||
end</pre> | end</pre> | ||
====Other methods==== | ====Other methods==== | ||
* [[MessageBox_Tutorial | * [[MessageBox_Tutorial/Quest_Scripts|Quests]] | ||
* [[MessageBox_Tutorial | * [[MessageBox_Tutorial/Token_Scripts|Tokens]] | ||
* [[MessageBox_Tutorial | * [[MessageBox_Tutorial/Spell_Scripts|Spells]] | ||
===What you'll need=== | ===What you'll need=== | ||
Line 315: | Line 311: | ||
===Activator=== | ===Activator=== | ||
#Select an activator in the "Object Window" | #Select an activator in the "Object Window" | ||
#*It needs to be an activator. Statics can't have scripts, [[ | #*It needs to be an activator. Statics can't have scripts, [[Crashes#Activating_a_Container_(including_NPC)|NPCs and containers can cause a CTD if they have a scripted item in their inventory]], and items can be picked up. | ||
#Edit the name | #Edit the name | ||
#Press enter (or select ok in the edit menu) | #Press enter (or select ok in the edit menu) | ||
Line 346: | Line 342: | ||
Begin GameMode | Begin GameMode | ||
If Working | If Working | ||
Set Working to 1 | |||
If (Choosing == 0) ;meaning it shouldn't be running | If (Choosing == 0) ;meaning it shouldn't be running | ||
Set Working to 0 | Set Working to 0 | ||
Line 370: | Line 368: | ||
Endif | Endif | ||
Endif | Endif | ||
Endif | Endif | ||
End</pre> | End</pre> | ||
Line 416: | Line 413: | ||
Begin GameMode | Begin GameMode | ||
If Working | If Working | ||
Set Working to 1 | |||
If (Choosing == 0) ;meaning it shouldn't be running | If (Choosing == 0) ;meaning it shouldn't be running | ||
Set Working to 0 | Set Working to 0 | ||
Line 525: | Line 524: | ||
Endif | Endif | ||
Endif | Endif | ||
Endif | Endif | ||
End</pre> | End</pre> | ||
Line 532: | Line 529: | ||
==Extras== | ==Extras== | ||
That will take care of most menu systems you'll ever want to create. However, there is still more functioniality you can add to your menus. From here, you can either get it all by using the following script, or pick and choose using the mini-tutorials: | That will take care of most menu systems you'll ever want to create. However, there is still more functioniality you can add to your menus. From here, you can either get it all by using the following script, or pick and choose using the mini-tutorials: | ||
<br>[[MessageBox_Tutorial | <br>[[MessageBox_Tutorial/Centralized_Decision_Catching|Centalizing your decision catching]] | ||
<br>[[Messagebox_Tutorial | <br>[[Messagebox_Tutorial/GameMode_And_MenuMode|Running menus in both GameMode and MenuMode when your script is too large]] | ||
<br>[[MessageBox_Tutorial | <br>[[MessageBox_Tutorial/Ensuring_Your_Menu_Is_Seen|Ensuring your menus are seen]] | ||
<br>[[Messagebox_Tutorial | <br>[[Messagebox_Tutorial/Set_Variables|Allowing the player to set a variable to any number]] | ||
<br>[[MessageBox_Tutorial | <br>[[MessageBox_Tutorial/External_Menu_Selection|Controlling the menu system via external scripts]] | ||
==Applying it all== | ==Applying it all== | ||
Line 542: | Line 539: | ||
<pre>scn YourMenuScript | <pre>scn YourMenuScript | ||
Short Working | |||
Short Choosing | Short Choosing | ||
Short Choice | Short Choice | ||
;GameMode and MenuMode variables | ;GameMode and MenuMode variables | ||
Line 553: | Line 548: | ||
;Ensuring Your Menu Is Read variables | ;Ensuring Your Menu Is Read variables | ||
Short MessageCounter | |||
Short | |||
Begin onActivate | Begin onActivate | ||
If (Choosing >= 0) | If (Choosing >= 0) ;Controlling the menu system via external scripts | ||
Set Choosing to -1 | Set Choosing to -1 | ||
Endif | Endif | ||
Set | Set Working to 1 | ||
If (MenuMode == 0) | Set MessageCounter to 0 ;Ensuring your menus are seen | ||
If (MenuMode == 0) ;Running menus in both GameMode and MenuMode | |||
Set GMRun to 1 | Set GMRun to 1 | ||
Endif | Endif | ||
End | End | ||
Line 573: | Line 565: | ||
Begin GameMode | Begin GameMode ;Running menus in both GameMode and MenuMode | ||
If (Choosing == 0) | If Working | ||
Set Working to 1 | |||
If (Choosing == 0) | |||
Set GMRun to 0 | |||
Set Working to 0 | |||
Set MessageCounter to 0 ;Ensuring your menu is seen | |||
;Add anything that needs to be re-initialized | |||
Elseif GMRun | |||
Set GMRun to 0 | |||
Set ExitButton to 0 | |||
Messagebox "Exiting options..." | |||
Elseif (Choice == -1) ;Ensuring your menus are seen | |||
if (MessageCounter < 30) | |||
set Choice to GetButtonPressed | |||
if (Choice == -1) | |||
if (MenuMode 1001 == 0) | |||
if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) && | |||
(MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) && | |||
(MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) && | |||
(MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) && | |||
(MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) && | |||
(MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) && | |||
(MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0) | |||
set MessageCounter to (MessageCounter + 1) | |||
endif | |||
else ;MenuMode 1001 | |||
set MessageCounter to 0 | |||
endif | |||
else ;Choice > -1 | |||
set MessageCounter to 0 | |||
endif | |||
else ;Display menu again | |||
set Choosing to -(Choosing) | |||
set MessageCounter to 0 | |||
message "Trying menu again..." | |||
Set | endif | ||
Elseif (Choice != ExitButton) | |||
Set ExitButton to 0 | |||
Messagebox "Exiting options..." | Messagebox "Exiting options..." | ||
Elseif (Choice == ExitButton) | |||
Set Choosing to 0 | |||
Endif | Endif | ||
Endif | Endif | ||
End | End | ||
Line 622: | Line 615: | ||
Begin MenuMode | Begin MenuMode | ||
If (Choosing == 0) | If Working | ||
Set Working to 1 | |||
; | |||
Set | If (Choosing == 0) | ||
Set GMRun to 0 ;Running menus in both GameMode and MenuMode | |||
Set Working to 0 | |||
Set MessageCounter to 0 ;Ensuring your menu is seen | |||
;Add anything that needs to be re-initialized | |||
;Ensuring your menu is seen | |||
;Centralizing your menu decisions | |||
Elseif (Choosing > 0) && (Choice == -1) ;No choice yet | |||
if (MessageCounter < 30) | |||
set Choice to GetButtonPressed | |||
if (Choice == -1) | |||
if (MenuMode 1001 == 0) | |||
if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) && | |||
(MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) && | |||
(MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) && | |||
(MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) && | |||
(MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) && | |||
(MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) && | |||
(MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0) | |||
set MessageCounter to (MessageCounter + 1) | |||
endif | |||
else ;MenuMode 1001 | |||
set MessageCounter to 0 | |||
endif | |||
else ;Choice > -1 | |||
set MessageCounter to 0 | |||
endif | |||
else ;Display menu again | |||
set Choosing to -(Choosing) | |||
set MessageCounter to 0 | |||
message "Trying menu again..." | |||
endif | |||
Elseif (Choosing == -1) ;Display your menu | |||
Set ExitButton to 1 ;Running menus in both GameMode and MenuMode | |||
Messagebox "What would you like to do?" "First Option" "Exit Menu" | |||
Set Choosing to 1 | |||
Set Choice to -1 | |||
Elseif (Choosing == 1) ;Catch the player's decision | |||
If (Choice == 0) ;First Option | |||
;run your code for the first decision | |||
Elseif (Choice == 1) ;Exit Menu | |||
;run your code for the second descision | |||
Set Choosing to 0 ;to finish up | |||
Endif | |||
;Allowing the player to set any number | |||
short NumNewIngsDefault | |||
elseif (Choosing == -2) | |||
set ExitButton to -2 ;Running menus in both GameMode and MenuMode | |||
messagebox "Set the default number of essences to be created. | |||
(Currently %g)", NumNewIngsDefault, | |||
"About 10 fewer (-12 to -8)" | |||
"About 5 fewer (-7 to -3)" | |||
"Default to that amount -2" | |||
"Default to that amount -1" | |||
"Default to that amount" | |||
"Default to that amount +1" | |||
"Default to that amount +2" | |||
"About 5 more (+3 to +7)" | |||
"About 10 more (+8 to +12)" | |||
"Return to previous menu" | |||
set Choosing to 2 | |||
set Choice to -1 | |||
elseif (Choosing == 2) | |||
if (Choice == 0) ;10 fewer | |||
set NumNewIngsDefault to (NumNewIngsDefault - 10) | |||
set Choosing to -2 | |||
elseif (Choice == 1) ;5 fewer | |||
set NumNewIngsDefault to (NumNewIngsDefault - 5) | |||
set Choosing to -2 | |||
elseif (Choice == 7) ;5 more | |||
set NumNewIngsDefault to (NumNewIngsDefault + 5) | |||
set Choosing to -2 | |||
elseif (Choice == 8) ;10 more | |||
set NumNewIngsDefault to (NumNewIngsDefault + 10) | |||
set Choosing to -2 | |||
elseif (Choice == 2) ;-2 | |||
set NumNewIngsDefault to (NumNewIngsDefault - 2) | |||
set Choosing to -1 | |||
elseif (Choice == 3) ;-1 | |||
set NumNewIngsDefault to (NumNewIngsDefault - 1) | |||
set Choosing to -1 | |||
elseif (Choice == 4) ;Cancel | |||
set Choosing to -1 | |||
elseif (Choice == 5) ;+1 | |||
set NumNewIngsDefault to (NumNewIngsDefault + 1) | |||
set Choosing to -1 | |||
elseif (Choice == 6) ;+2 | |||
set NumNewIngsDefault to (NumNewIngsDefault + 2) | |||
set Choosing to -1 | |||
elseif (Choice == 9) ;Return to previous menu | |||
set Choosing to -1 | |||
endif | |||
Endif | Endif | ||
Endif | Endif | ||
End</pre> | End</pre> | ||
[[Category: Scripting Tutorials]] | [[Category: Scripting Tutorials]] |