Difference between revisions of "MessageBox Tutorial/Quest Scripts"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
(Created)
 
imported>Haama
(Removed from category)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Some background==
==Some background==
Quest scripts are very similar to the activator script. You won't need to do the extra coding that an [[MessageBox_Tutorial#Activator_Disadvantages|activator requires]], so they'll be a bit easier.
Quest scripts are very similar to the activator script. However, just like the activator script the quest script will require a bit of extra coding.


The disadvantage of quests lies in their lack of a clear start. That is, there are no blocks that a quest runs only a single time when it first starts. Instead, the entire script is run every frame. For instance, if we put the onActivate block into the GameMode block:
The disadvantage of quests lies in their lack of a clear start. That is, there are no blocks that a quest runs only a single time when it first starts. Instead, the entire script is run every frame. For instance, if we put the onActivate block into the GameMode block:
Line 18: Line 18:


==Setup==
==Setup==
# Open the quest dialog. Select a quest on the left. Right-click it and select new. Name it accordingly (YourMenu in this tutorial).
# Create a new quest: Open the quest dialog. Select a quest on the left. Right-click it and select new. Name it accordingly (YourMenu in this tutorial).
# Write the script:
# Write the script:
<pre>scn YourMenuScript
<pre>scn YourMenuScript
Line 24: Line 24:
Short Choice
Short Choice
Short Working
Short Working
Float fQuestDelayTime




Line 35: Line 36:


   If (Choosing == 0) ;meaning it shouldn't be running
   If (Choosing == 0) ;meaning it shouldn't be running
    StopQuest YourMenuScript
    ;Add anything that needs to be re-initialized
     Return
     Return


   Elseif (Choosing == -1) ;Display your menu
   Elseif (Choosing == -1) ;Display your menu
     Messagebox "Which option?" "First Option" "Second Option" ;...
     Messagebox "Which option?" "First Option" "Second Option" ... "Tenth Option"
     Set Choosing to 1
     Set Choosing to 1
     Set Choice to -1
     Set Choice to -1
   Elseif (Choosing == 1) ;Catch the player's decision
   Elseif (Choosing == 1) ;Catch the player's decision
     If (Choice == -1) ;No choice yet
     If (Choice == -1) ;No choice yet
Line 52: Line 53:
       ;run your code for the second decision
       ;run your code for the second decision
       Set Choosing to 0 ;to finish up
       Set Choosing to 0 ;to finish up
;...  
;...
;Further illustrations of more options
;   Elseif (Choice == 9) ;Tenth Option
;    Elseif (Choice == #) ;Nth Option
      ;run your code for the tenth decision
      ;run your code for the nth decision
;     Set Choosing to 0 ;to finish up
;      Set Choosing to 0
 
;    Elseif (Choice == 9) ;Final/Tenth Option
      ;run your code for the tenth decision
;     Set Choosing to 0
     Endif
     Endif
   Endif
   Endif
Line 65: Line 63:
# Make sure to save the script as a Quest Script.
# Make sure to save the script as a Quest Script.
# Attach the script to the quest.
# Attach the script to the quest.
# You can start your menus from any script with <pr>set YourMenu.Working to 1</pre>.
# You can start your menus from any script with
<pre>set YourMenu.fQuestDelayTime to .01
set YourMenu.Working to 1
StartQuest YourMenu</pre>


==Notes on using StartQuest/StopQuest==
==Notes on using StartQuest/StopQuest==
You can use StopQuest and StartQuest to control when the quest is running. This will prevent the extra '''if''' tests from running, but:
The above uses StopQuest and StartQuest to control when the quest is running. This will prevent the extra '''if''' lines from running when they doesn't need to be. [StartQuest#Notes|Be careful when using StartQuest and make sure you don't start it when it's already running.]
# You will need to remember to stop it
 
<pre>...
The other option is to let the script run all the time. Use the same scripts as above but get rid of the StartQuest and StopQuest lines and set the quest to '''Start Game Enabled'''.
  if (Choosing == 0)
    StopQuest YourMenu
...</pre>
# You will need to remember to use
<pre>set YourMenu.Working to 1
StartQuest YourMenu</pre>
every time you want to use it.
# It will take a couple of seconds after using [[StartQuest]] before the quest starts up.
# Using ''StartQuest'' can be dangerous, as using ''StartQuest'' on a quest that is already running will reset all of it's variables to 0.

Latest revision as of 18:07, 3 June 2008

Some background[edit | edit source]

Quest scripts are very similar to the activator script. However, just like the activator script the quest script will require a bit of extra coding.

The disadvantage of quests lies in their lack of a clear start. That is, there are no blocks that a quest runs only a single time when it first starts. Instead, the entire script is run every frame. For instance, if we put the onActivate block into the GameMode block:

begin GameMode
  set Choosing to -1
  if (Choosing == -1)
...

then the first menu will be displayed continuously.

To fix this, we need to add another variable:

begin GameMode
  if (Working == 1)
    set Choosing to -1
    set Working to 0
  endif
...

Setup[edit | edit source]

  1. Create a new quest: Open the quest dialog. Select a quest on the left. Right-click it and select new. Name it accordingly (YourMenu in this tutorial).
  2. Write the script:
scn YourMenuScript
Short Choosing
Short Choice
Short Working
Float fQuestDelayTime



Begin GameMode
  If (Working == 1)
    Set Choosing to -1
    Set Working to 0
  Endif


  If (Choosing == 0) ;meaning it shouldn't be running
    StopQuest YourMenuScript
    ;Add anything that needs to be re-initialized
    Return

  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
  1. Make sure to save the script as a Quest Script.
  2. Attach the script to the quest.
  3. You can start your menus from any script with
set YourMenu.fQuestDelayTime to .01
set YourMenu.Working to 1
StartQuest YourMenu

Notes on using StartQuest/StopQuest[edit | edit source]

The above uses StopQuest and StartQuest to control when the quest is running. This will prevent the extra if lines from running when they doesn't need to be. [StartQuest#Notes|Be careful when using StartQuest and make sure you don't start it when it's already running.]

The other option is to let the script run all the time. Use the same scripts as above but get rid of the StartQuest and StopQuest lines and set the quest to Start Game Enabled.