GetButtonPressed

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Syntax:

GetButtonPressed 

Example:

set buttonVar to GetButtonPressed 


The first time this is called after a MessageBox button has been pressed, it returns the button number (0 indicates the first button, 1 the second, etc.). At all other times it returns -1.

Example

int button
int buttonPressed

Begin OnActivate
  if IsActionRef player == 1
    messagebox "You have 3 choices.", "Choice 1", "Choice 2", "Choice 3"
    set buttonPressed to 1
  endif
end

begin gamemode
  if buttonPressed == 1
    set button to getbuttonpressed

    if button > -1
      if button == 0
        ; choice 1
        set buttonPressed to 0
      elseif button == 1
        ; choice 2
        set buttonPressed to 0
      elseif button == 2
        ; choice 3
        set buttonPressed to 0
      endif
    endif
  endif
end

Notes[edit | edit source]

  • This will only react to a MessageBox created from within the same script.
  • Be careful when using this function in a magic spell script. If the target has a script that also uses GetButtonPressed only one of the scripts will return the correct response. For instance, if the target has this object script
    begin onActivate
      messagebox "Counterfeit money?" "Yes" "No"
    end
    
    begin GameMode
      set button to GetButtonPressed
      if button == 0
        player.AddItem Gold001 1000
      endif
    end

    and the spell has this script

    begin ScriptEffectStart
      messagebox "Melt money?" "Yes" "No"
    end
    
    begin ScriptEffectUpdate
      set choice to GetButtonPressed
      if choice == 0
        player.RemoveItem Gold001 1000
      endif
    end
    when you cast the spell and select "Yes", the object script may run first and add money to the player, but not remove it (as the spell's GetButtonPressed will return -1).
    • In general, a magic spell with GetButtonPressed will be safe to use on the player, but you take a much larger chance with any other object.
    • Using this in a spell script requires the spell Duration to be greater than 0 in order for the game to have time to capture the button pressed.

GameMode or MenuMode?[edit | edit source]

Once the player has pressed a button, thus exiting the menu, it will take about another 15 frames before GetButtonPressed returns the player's decision. If the menu was started from a GameMode block, then exiting the menu will return the player to GameMode, and you should use GetButtonPressed in a GameMode block. Likewise, if the menu was started from a MenuMode block, the exiting the menu will return the player to MenuMode, and you should use GetButtonPressed in a general MenuMode block or that specific MenuMode block.

If you're using GetButtonPressed in a Magic Effect Script, note that the ScriptEffect... blocks will only run in GameMode. This means that you will need 15-20 frames for every menu displayed, to make sure GetButtonPressed returns the player's choice. For a single menu, you should give your spell a duration of at least 3 seconds. For multi-layered menus, you will want more time, maybe 30 seconds or so.

See Also[edit | edit source]