Difference between revisions of "MenuMate Tutorial"
Jump to navigation
Jump to search
imported>Speedo (→XML) |
imported>Speedo (→Script) |
||
Line 15: | Line 15: | ||
scn BankDemoScript | scn BankDemoScript | ||
int accountBalance | int accountBalance | ||
ref playerRef | ref playerRef | ||
int playerGold | int playerGold | ||
int minVar | int minVar | ||
int temp | int temp | ||
int invert | int invert | ||
int displayStatus | |||
float fQuestDelayTime | |||
begin MenuMode | |||
if (displayStatus) | |||
mmUpdate | |||
endif | |||
end | |||
begin GameMode | begin GameMode | ||
set fQuestDelayTime to 0.0001 | |||
set | |||
if (displayStatus == 0) | |||
set playerRef to player | |||
StopQuest BankDemo | set playerGold to player.GetItemCount Gold001 | ||
set minVar to 0 | |||
set temp to 0 | |||
set invert to 0 | |||
if (mmLoadMenu "demo.xml") | |||
set displayStatus to 1 | |||
else | |||
PrintC "menu failed to load" | |||
StopQuest BankDemo | |||
endif | |||
elseif (mmGetStatus == 1) | |||
set displayStatus to 0 | |||
StopQuest BankDemo | |||
endif | |||
end | end | ||
</pre> | </pre> |
Latest revision as of 20:56, 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[edit | edit source]
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[edit | edit source]
Script[edit | edit source]
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 ref playerRef int playerGold int minVar int temp int invert int displayStatus float fQuestDelayTime begin MenuMode if (displayStatus) mmUpdate endif end begin GameMode set fQuestDelayTime to 0.0001 if (displayStatus == 0) set playerRef to player set playerGold to player.GetItemCount Gold001 set minVar to 0 set temp to 0 set invert to 0 if (mmLoadMenu "demo.xml") set displayStatus to 1 else PrintC "menu failed to load" StopQuest BankDemo endif elseif (mmGetStatus == 1) set displayStatus to 0 StopQuest BankDemo endif end
XML[edit | edit source]
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>