Difference between revisions of "MenuMate Tutorial"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Speedo
(created)
 
imported>Speedo
Line 44: Line 44:


<menu>
<menu>
   <start>main</start>
   <start name="main"/>
   <dialog>deposit</dialog>
   <dialog name="deposit"/>
   <dialog>withdraw</dialog>
   <dialog name="withdraw"/>
  <dialog name="buttondemo"/>
</menu>
</menu>


<main>
<main>
   <text format="Greetings %n!%rYour balance is %.0f gold, what do you wish to do?">
   <text format="Greetings %n!%rYour balance is %.0f gold, what do you wish to do?">
     <param>playerRef</param>
     <param name="playerRef"/>
     <param>accountBalance</param>
     <param name="accountBalance"/>
   </text>
   </text>
    
    
Line 68: Line 69:
</main>
</main>


<!-- This dialog inverts its counterbuttons via a togglebutton + toggle variable -->
<deposit>
<deposit>
   <text format="Deposit Amount: %.0f%rYou have %.0f gold">
   <text format="Deposit Amount: %.0f%rYou have %.0f gold">
     <param>temp</param>
     <param name="temp"/>
     <param>playerGold</param>
     <param name="playerGold"/>
   </text>
   </text>
    
    
Line 97: Line 99:
     <text format="Finish"/>
     <text format="Finish"/>
     <script>
     <script>
       set BankDemo.accountBalance to BankDemo.accountBalance + BankDemo.temp &amp;#10;
       set BankDemo.accountBalance to BankDemo.accountBalance + BankDemo.temp &#10;
       player.RemoveItem 0000000F BankDemo.temp &amp;#10;
       player.RemoveItem 0000000F BankDemo.temp &#10;
       MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
       MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
     </script>
     </script>
Line 108: Line 110:
</deposit>
</deposit>


<!-- This dialog makes use of the toggle key(s) to invert its counters -->
<withdraw>
<withdraw>
   <text format="Withdraw Amount: %.0f%rYour balance is %.0f gold">
   <text format="Withdraw Amount: %.0f%rYour balance is %.0f gold%r%rHold one of these keys to decrease the amount: [INVERTKEYS]">
     <param>temp</param>
     <param name="temp"/>
     <param>accountBalance</param>
     <param name="accountBalance"/>
   </text>
   </text>
    
    
  <togglebutton targetvar="invert" truetext="subtracting" falsetext="adding">
   <counterbutton targetvar="temp" amount="1" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="Toggle Add/Subtract%r(currently [STATE])"/>
  </togglebutton>
 
   <counterbutton targetvar="temp" amount="1" invertvar="invert" maxvar="accountBalance" minvar="minVar">
     <text format="[STATE]"/>
     <text format="[STATE]"/>
   </counterbutton>
   </counterbutton>
    
    
   <counterbutton targetvar="temp" amount="10" invertvar="invert" maxvar="accountBalance" minvar="minVar">
   <counterbutton targetvar="temp" amount="10" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
     <text format="[STATE]"/>
     <text format="[STATE]"/>
   </counterbutton>
   </counterbutton>
    
    
   <counterbutton targetvar="temp" amount="100" invertvar="invert" maxvar="accountBalance" minvar="minVar">
   <counterbutton targetvar="temp" amount="100" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
     <text format="[STATE]"/>
     <text format="[STATE]"/>
   </counterbutton>
   </counterbutton>
    
    
   <counterbutton targetvar="temp" amount="1000" invertvar="invert" maxvar="accountBalance" minvar="minVar">
   <counterbutton targetvar="temp" amount="1000" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
     <text format="[STATE]"/>
     <text format="[STATE]"/>
   </counterbutton>
   </counterbutton>
Line 137: Line 136:
     <text format="Finish"/>
     <text format="Finish"/>
     <script>
     <script>
       set BankDemo.accountBalance to BankDemo.accountBalance - BankDemo.temp &amp;#10;
       set BankDemo.accountBalance to BankDemo.accountBalance - BankDemo.temp &#10;
       player.AddItem 0000000F BankDemo.temp &amp;#10;
       player.AddItem 0000000F BankDemo.temp &#10;
       MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
       MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
     </script>
     </script>

Revision as of 20:55, 7 December 2008

This tutorial shows a basic example of menu creation with MenuMate. We will create a basic menu interface for a bank-type mod, which allows the player to deposit and withdraw money from a bank account. The menu created in this tutorial is included in the MenuMate download.

Goals

Our menu will consist of three dialogs:

  • The main menu. Will show the player their account balance and allow them to choose between making a deposit or withdrawal.
  • The deposit menu. Allows the player to enter an amount of gold to deposit, up to the amount they currently are carrying.
  • The withdrawal menu. Allows the player to enter an amount of gold they wish to withdraw from their account, up to their current account balance.

Implementation

Script

We still need a small script to support our menu XML. This script will display the menu and contain several variables used by the menu.

scn BankDemoScript

int accountBalance ; player's account balance

ref playerRef ; ref used to display the player's name
int playerGold ; player's current gold
int minVar ; minimum amount for the counterbuttons
int temp ; used for player input
int invert ; toggle for the inversion of the counterbuttons

begin GameMode
  ; initialize the variables
  set playerRef to player
  set playerGold to player.GetItemCount Gold001
  set minVar to 0
  set temp to 0
  set invert to 0
  
  ; display the menu
  mmLoadMenu "demo.xml"
  StopQuest BankDemo
end

XML

The XML of our desired menu is as follows:

<?xml version="1.0" ?>

<menu>
  <start name="main"/>
  <dialog name="deposit"/>
  <dialog name="withdraw"/>
  <dialog name="buttondemo"/>
</menu>

<main>
  <text format="Greetings %n!%rYour balance is %.0f gold, what do you wish to do?">
    <param name="playerRef"/>
    <param name="accountBalance"/>
  </text>
  
  <linkbutton target="deposit">
    <text format="Make a deposit"/>
  </linkbutton>
  
  <linkbutton target="withdraw">
    <text format="Withdraw money"/>
  </linkbutton>
  
  <exitbutton>
    <text format="Nothing"/>
  </exitbutton>
</main>

<!-- This dialog inverts its counterbuttons via a togglebutton + toggle variable -->
<deposit>
  <text format="Deposit Amount: %.0f%rYou have %.0f gold">
    <param name="temp"/>
    <param name="playerGold"/>
  </text>
  
  <togglebutton targetvar="invert" truetext="subtracting" falsetext="adding">
    <text format="Toggle Add/Subtract%r(currently [STATE])"/>
  </togglebutton>
  
  <counterbutton targetvar="temp" amount="1" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="10" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="100" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="1000" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <exitbutton>
    <text format="Finish"/>
    <script>
      set BankDemo.accountBalance to BankDemo.accountBalance + BankDemo.temp 

      player.RemoveItem 0000000F BankDemo.temp 

      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</deposit>

<!-- This dialog makes use of the toggle key(s) to invert its counters -->
<withdraw>
  <text format="Withdraw Amount: %.0f%rYour balance is %.0f gold%r%rHold one of these keys to decrease the amount: [INVERTKEYS]">
    <param name="temp"/>
    <param name="accountBalance"/>
  </text>
  
  <counterbutton targetvar="temp" amount="1" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="10" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="100" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="1000" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <exitbutton>
    <text format="Finish"/>
    <script>
      set BankDemo.accountBalance to BankDemo.accountBalance - BankDemo.temp 

      player.AddItem 0000000F BankDemo.temp 

      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</withdraw>