nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Wed Sep 01, 2004 12:47 pm
[HOW-TO] Using Data(base) Variables |
First thing to get out of your head is that a Database Variable does not mean your using the database module in Zmud. It does make adding stuff to the DB alot easier if your so inclined though :P
When you get more advanced in zmud you find yourself having alot of variables for a complex trigger sometimes this gets really confusing when your trying to remember what the var hpc means! the solution: Database Variables (data records). NOTE The zmud command for this is #ADDKEY but we will be using the short table.var=value syntax. Using data records also gives you the ULTIMATE looping command #LOOPDB
On my mud I have a very complex prompt and I have to base a lot of my actions off of how much mana I have or what position I am in. So I store everything in a single PROMPT variable instead of 8+ variables that I might forget what they are for.
Examples using reg variables:
#TR {^~[HP:(%d)/(%d) MA:(%d)/(%d)} {hp=%1;maxhp=%2;ma=%3;maxma=%4} "" {prompt|nocr}
#TR {^~[HP:&%d{hp}/&%d{maxhp} MA:&%d{ma}/&%d{maxma}} {} "" {prompt|nocr}
The first example uses regular pattern matching to store the variable values. and the second method uses the database char to store the value to a variable. the first option is more flexible though
Now lets do the same thing using a single data record:
#TR {^~[HP:(%d)/(%d) MA:(%d)/(%d)} {prompt.hp=%1;prompt.maxhp=%2;prompt.ma=%3;prompt.maxma=%4} "" {prompt|nocr}
#TR {^~[HP:&%d{prompt.hp}/&%d{prompt.maxhp} MA:&%d{prompt.ma}/&%d{prompt.maxma}} {} "" {prompt|nocr}
Notice that the only thing we changed was to add "prompt." to the begining of the var name. Now if we look in the settings editor we will see a single variable (database table)called "prompt" which contains 4 variable/value pairs.
Well lets say we want to use the value of one of the vars you can't quite use #SAY @hp as we don't have an @hp anymore. What we do instead is say that we want the value of hp in the prompt table (var) #SAY @prompt.hp note that all we did was add a "prompt." to the begining of the variable name.
Now lets say we want to clear EVERYTHING in the prompt data record. Well its easy we use just one command. prompt="" instead of going through each individule variable and deleting the value.
Another thing this is handy for are Autorollers
Simple deflated example using data record and trigger states (#COND).
Here are your stats.
Str: 50
Dex: 25
Int: 20
Do you want to keep these stats? [y/n]>
#TR {Here are your stats.} {roll="";total=0} //set the roll data record to null and the total variable to 0
#COND {Str: &%d{roll.str}} {} //create the roll.str var
#COND {Dex: &%d{roll.dex}} {} //create the roll.dex var
#COND {Int: &%d{roll.int}} {} //create the roll.int var
#COND {Do you want to keep these stats ~[y/n~]~>} {#LOOPDB @roll {#ADD total %val}
#IF (((@roll.str>=40) AND (@roll.dex>=50) AND (@roll.int>=30)) OR (@total=>150)) {
#BEEP
#ECHO Its' a match do you approve?} {n}} "" {prompt|nocr}
// This is the trigger that loops through the DB and adds the total then compare is the stats are either all above the specified minimum OR if the toal roll is greater then 150. IF it is then beep and echo the user ELSE reroll.
If you still don't understand Ask in this topic for some more help I just got out of work so Im a we bit tired but wanted to get this done so lemme know if I missed some stuff too. Start a new topic for specific mud problems please. |
|