MessageBox Tutorial/Token Scripts
(Redirected from MessageBox Tutorial: Token Scripts)
Jump to navigation
Jump to search
Some Background[edit | edit source]
Like activators, tokens have a clear beginning. Since they will be added to the player, they will always be loaded and won't require extra coding. However, they can cause CTDs (which aren't very likely in this case), and may cause other problems. Also, they aren't persistent objects, so if there are any variables you would like to use in other scripts, you will need to "upload" them to another persistent object (quest or any object marked "Persistent Object").
Setup[edit | edit source]
- Create a new item: Open the Object Window, double-click an item (or right click it and select "Edit"), give it a new EditorID, select "Yes" when asked if you want to create a new item/FormID.
- If you would like to create an item the player can't see in their inventory, select a clothing item, create the new item, and de-select "Playable".
- Attach this script to it:
scn YourMenuScript Short Choosing Short Choice Begin onAdd Set Choosing to -1 End Begin GameMode If (Choosing == 0) ;meaning it shouldn't be running ;Add anything that needs to be re-initialized RemoveMe ;acts as a return, so be sure everything is done Elseif (Choosing == -1) ;Display your menu Messagebox "Which option?" "First Option" "Second Option" ... "Tenth Option" Set Choosing to 1 Set Choice to -1 Elseif (Choosing == 1) ;Catch the player's decision If (Choice == -1) ;No choice yet Set Choice to GetButtonPressed Elseif (Choice == 0) ;First Option ;run your code for the first decision Set Choosing to 0 ;to finish up Elseif (Choice == 1) ;Second Option ;run your code for the second decision Set Choosing to 0 ;to finish up ;... ; Elseif (Choice == 9) ;Tenth Option ;run your code for the tenth decision ; Set Choosing to 0 ;to finish up Endif Endif End
- Add the item to the player when you want to run the menu (player.AddItem YourItem 1).
Notes[edit | edit source]
- If you want to store any variables set on the token, you will need a persistent object. Set the variables you want to store on the persistent object, as such set YourPersistentObject.SomeVar to SomeVar.
- While it is not absolutely necessary to remove the token, it does make scripting easier as there is a clear beginning and a clear end. If you want to keep the token (for instance, to keep the variables on it), then you can remove it to a remote container (RemoveMe RemoteCont), and move it back to the player when you want to use it again. There are 2 ways to move it back to the player:
- Use RemoteCont.RemoveAllItems player. RemoveAllItems will only move Playable items. You can use this if each token is a unique item (unique FormID) and a piece of clothing. Use SetIsPlayable (OBSE v.0012) to toggle the items between Playable and Unplayable.
- Otherwise, you can mark each token with a unique number (set a short variable). This number can be used to determine if the token should remove itself back to the player (RemoveMe player). Make each token check a persistent variable (global, quest variable, or persistent object variable) every frame, and load the remote container by setting a variable on it or moving it to the player (be sure to move it back afterwards).
short ID begin onAdd if (ID == 0) set ID to PersistentObject.SomeVar endif end begin GameMode if (PersistentObject.SomeVar == ID) set PersistentObject.SomeVar to 0 RemoveMe player endif ... ;Rest of menu script