MessageBox Tutorial/Spell Scripts
From The Elder Scrolls Construction Set Wiki
[edit] 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.
The quest script:
scn MenuVariablesScript Short Choosing Short Choice
The spell script:
Short Choosing
Short Choice
Short DoOnce
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
;Following section is to add spell effect when choice is made and
;to dispel the spell so it doesn't appear to still be active
If (DoOnce == 0)
PlayMagicShaderVisuals ;place effect shader Editor ID here i.e. effectEnchantMysticism
Set DoOnce to 1
Set Timer to 4
ElseIf (Timer > 0)
Set Timer to Timer - GetSecondsPassed
ElseIf (Timer < 0)
StopMagicShaderVisuals ;place effect shader Editor ID here i.e. effectEnchantMysticism
Set Timer to 0
TargetRef.Dispel Spell
EndIf
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
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
[edit] Notes
- This should only be used for spells cast on the player. If the target's script already uses GetButtonPressed, it may interfere with this menu (see GetButtonPressed for more details). That will probably never happen for the player, but any other object is questionable.
- 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 and TargetRef.Dispel Spell) must be replaced with Editor ID of the Spell using the script

