Difference between revisions of "MessageBox Tutorial"

Jump to navigation Jump to search
283 bytes added ,  09:29, 25 August 2007
imported>ShadowDancer
imported>Haama
Line 318: Line 318:


===Multiple Menus in a Spell Script===
===Multiple Menus in a Spell Script===
Below is an example of multiple menus in a spell script. '''Step''' is used to control the stages of [[ScriptEffectUpdate]] for the '''MessageBox''' and the '''GetButtonPressed''' functions. While the initial '''MessageBox''' for the spell could have been in the [[ScriptEffectStart]], it is in the '''ScriptEffectUpdate''' block for clarity. Most of the button names as well as scripting have been left out so that the basics of manipulating multiple '''MessageBox''' functions can be seen.
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.


<pre> ScriptName ExampleScript
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.
 
Short Step
Note also that, as of now, this hasn't been tested for multiple menus.
Short ButtonChoice1
 
Short ButtonChoice2
The quest script:
{Set Other Variables}
<pre>scn MenuVariablesScript
 
Short Choosing
Begin ScriptEffectStart
Short Choice</pre>
 
{Set up start of Spell}
The spell script:
Set Step to 1
<pre>Short Choosing
Short Choice
End
 
 
 
Begin ScriptEffectUpdate
Begin SpellEffectStart
  if MenuVariables.Choosing
  If Step == 1
    Set Choosing to MenuVariables.Choosing
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Next Page"
    Set Choice to MenuVariables.Choice
    Set Step to 2
  else
  EndIf
    Set Choosing to -1
  endif
  If Step == 2
End
    Set ButtonChoice1 to GetButtonPressed
 
    If ButtonChoice1 == 0
 
      {script to do whatever button is for}
 
      Set Step to 0
Begin SpellEffectUpdate
    ElseIf ButtonChoice1 == 1
  If (Choosing == 0) ;meaning it shouldn't be running
      {script to do whatever button is for}
    set MenuVariables.Choosing to 0
      Set Step to 0
    set MenuVariables.Choice to 0
    ElseIf ButtonChoice1 == 2
    Return
      {script to do whatever button is for}
 
      Set Step to 0
 
    ElseIf ButtonChoice1 == 3
  Elseif (Choosing == -1) ;Display your menu
      {script to do whatever button is for}
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Next Page"
      Set Step to 0
    Set Choosing to 1
    ElseIf ButtonChoice1 == 4
    Set Choice to GetButtonPressed
      {script to do whatever button is for}
    Return
      Set Step to 0
 
    ElseIf ButtonChoice1 == 5
  Elseif (Choosing == 1)
      {script to do whatever button is for}
    If (Choice == -1) ;No choice yet
      Set Step to 0
      Set Choice to GetButtonPressed
    ElseIf ButtonChoice1 == 6
      Return
      {script to do whatever button is for}
    Elseif (Choice == 0) ;Button0
      Set Step to 0
      ;Whatever you want to do
    ElseIf ButtonChoice1 == 7
      Set Choosing to 0
      {script to do whatever button is for}
...
      Set Step to 0
    Elseif (Choice == 8) ;Button8
    ElseIf ButtonChoice1 == 8
      ;Whatever you want to do
      {script to do whatever button is for}
      Set Choosing to 0
      Set Step to 0
    Elseif (Choice == 9) ;Next Page
    ElseIf ButtonChoice1 == 9
      Set Choosing to -2 ;Following menu (choosing == -2)
      Set Step to 3
    Endif
    EndIf
    Return
  EndIf
 
  Elseif (Choosing == -2) ;Gold menu
  If Step == 3
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Exit"
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button2"], "Quit"
    Set Choosing to 2
    Set Step to 4
    Set Choice to GetButtonPressed
  EndIf
    Return
 
  If Step == 4
  Elseif (Choosing == 2)
    Set ButtonChoice2 to GetButtonPressed
    If (Choice == -1) ;No choice yet
    If ButtonChoice2 == 0
      Set Choice to GetButtonPressed
      {script to do whatever button is for}
    Elseif (Choice == 0) ;Button0
      Set Step to 0
      ;Whatever you want to do
    ElseIf ButtonChoice2 == 1
      set Choosing to 0
      {script to do whatever button is for}
    ...
      Set Step to 0
    Elseif (Choice == 8) ;Button8
    ElseIf ButtonChoice2 == 2
      ;Whatever you want to do
      {script to do whatever button is for}
      Set Choosing to 0
      Set Step to 0
    Elseif (Choice == 9) ;Exit
    ElseIf ButtonChoice2 == 3
      Set Choosing to 0 ;to close the menus
      Set Step to 0
    Endif
    EndIf
    Return
  EndIf
 
 
End</pre>
  Endif
End
 
 
 
begin ScriptEffectFinish
  if Choosing
    set MenuVariables.Choosing to Choosing
    set MenuVariables.Choice to Choice
    player.Cast Spell
  endif
end</pre>


'''Notes:'''
'''Notes:'''
Anonymous user

Navigation menu