Difference between revisions of "MessageBox Tutorial"

3,437 bytes removed ,  13:04, 29 August 2007
imported>Haama
imported>Haama
Line 539: Line 539:




===Multiple Menus in a Spell Script===
A spell presents several challenges for multiple menus, but it can be done. Most importantly, you will need to set a high duration on the spell (see [[GetButtonPressed#GameMode or MenuMode?]]). However, the player could still open enough menus to run down the duration, no matter how long. To cover this scenario, all of the menu variables will be copied to a persistent object (in this case, the quest MenuVariables) when the spell runs out, and the spell will be recast.


This leads to one more small problem - if the variables are left set, then every time the spell is cast the menu would start more it left off before (well, ok, this could be cool, but I'll assume it's undesirable). To solve this, all of the external menu variables will be reset when the player exits the menu.
Note also that, as of now, this hasn't been tested for multiple menus.
The quest script:
<pre>scn MenuVariablesScript
Short Choosing
Short Choice</pre>
The spell script:
<pre>Short Choosing
Short Choice
Ref TargetRef
Begin SpellEffectStart
  Set TargetRef to GetSelf
  if MenuVariables.Choosing
    Set Choosing to MenuVariables.Choosing
    Set Choice to MenuVariables.Choice
  else
    Set Choosing to -1
  endif
End
Begin SpellEffectUpdate
  If (Choosing == 0) ;meaning it shouldn't be running
    set MenuVariables.Choosing to 0
    set MenuVariables.Choice to 0
  Elseif (Choosing == -1) ;Display your menu
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Next Page"
    Set Choosing to 1
    Set Choice to GetButtonPressed
  Elseif (Choosing == 1)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
      Return
    Elseif (Choice == 0) ;Button0
      ;Whatever you want to do
      Set Choosing to 0
...
    Elseif (Choice == 8) ;Button8
      ;Whatever you want to do
      Set Choosing to 0
    Elseif (Choice == 9) ;Next Page
      Set Choosing to -2 ;Following menu (choosing == -2)
    Endif
  Elseif (Choosing == -2) ;Gold menu
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Exit"
    Set Choosing to 2
    Set Choice to GetButtonPressed
  Elseif (Choosing == 2)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;Button0
      ;Whatever you want to do
      set Choosing to 0
    ...
    Elseif (Choice == 8) ;Button8
      ;Whatever you want to do
      Set Choosing to 0
    Elseif (Choice == 9) ;Exit
      Set Choosing to 0 ;to close the menus
    Endif
  Endif
End
begin ScriptEffectFinish
  if Choosing
    set MenuVariables.Choosing to Choosing
    set MenuVariables.Choice to Choice
    TargetRef.Cast Spell TargetRef
  endif
end</pre>
'''Notes:'''
* Using multiple menus, or catching a button press with [[GetButtonPressed]] in a magic effect script requires that the spell duration be more than 0 in order for '''GetButtonPressed''' to capture the button.
* The [[ScriptEffectFinish]] block will always run immediately after the last running of the [[ScriptEffectUpdate]] block. Due to this, if the '''ScriptEffectUpdate''' block has a '''Return''' statement that fires at this point of the script, the '''ScriptEffectFinish''' block will not run.
* Spell using the script must have a '''Range''' of ''Self''
* ''Spell'' in the above script (TargetRef.Cast ''Spell'' TargetRef) must be replaced with '''Editor ID''' of the Spell using the script


==Extras==
==Extras==
Anonymous user