|
Christopher Beginner
Joined: 01 May 2004 Posts: 11 Location: USA
|
Posted: Fri May 07, 2004 6:53 pm
Database/addkey question |
I'm trying to learn how to use databases in Zmud and my test case seems simple but I'm struggling with it. I would like to read in my stat training values, and then have an output of which stat is cheapest to train and should be my next train. The mud output looks like this:
Int: 48.54M (16) Wis: 48.54M (16) Str: 42.10M (15)
Con: 42.10M (15) Cha: 27.48M (12) Dex: 42.10M (15)
The trigger I'm using to read in looks like this:
(%w): (%x)M ?(%d)? (%w): (%x)M ?(%d)? (%w): (%x)M ?(%d)?
This correctly reads 9 values from each line of data (tested by echoing %i for all of them. The commands I'm trying are:
#ADDKEY stats {stat=%1|cost=%2|number=%3|stat=%4|cost=%5|number=%6|stat=%7|cost=%8|number=%9}
#LOOPDB @stats {#SHOW %key "=" %val}
And the output from that is:
stat = Str
stat = Dex
cost = 42.10
number = 15
cost = 42.10
number = 15
I'm not quite sure what I'm doing wrong, but any suggestions are welcome. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Fri May 07, 2004 7:37 pm |
Well your trigger is correct just not the way your using AddKey Try something like this to give you something to work with
#ADDKEY stats {%1_cost=%2|%1_number=%3|%4_cost=%5|%4_number=%6|%7_cost=%8|%7_number=%9} |
|
|
|
Christopher Beginner
Joined: 01 May 2004 Posts: 11 Location: USA
|
Posted: Fri May 07, 2004 7:43 pm |
Nexela,
You are a scholar and a gentleman, that seems to have done the trick, now I just need to figure out the minmize and display part.
Thanks much! |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Fri May 07, 2004 8:55 pm |
Untested roughness
#LOOPDB @stats {#if (%val=%min(@stats.str_cost,@stats.con_cost,etc)) {#show Key "=" %val}} |
|
|
|
Christopher Beginner
Joined: 01 May 2004 Posts: 11 Location: USA
|
Posted: Fri May 07, 2004 9:06 pm |
Again, thanks for the input, ideally, I'm trying to learn how to build databases and how to access and query them. I'm thinking that a database of stats to train would be a good place to start, I was envisioning a database (or table really) something like this
Stat | Cost to train | Number trained
Int 45.54M 15
Wis 43.34M 14
Str etc.
Dex
Con
Cha
Then I could search for the minimum of the Cost to train column, and reference back to which stat I can train, the display would then tell me what the cheapest stat to train is and which stat that is as well as how many I had trained.
Thanks for your help, after doing more reading, I think what I need to do is start using the #new command to input records to an actual database rather than just a database variable. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat May 08, 2004 6:37 am |
Record variables only allow you to match each key with one value only and each key must be unique. Since you want to match each Stat with both its Cost to Train and its Number Trained, you either need two variables, or a database with three fields, or you need to combine the Stat name with "Cost" and "Number" (Int_Cost, Int_Number) to provide two keys per stat.
For six stats which will change frequently, two variables is probably the easiest choice. Also, since these two lines should always appear together, its convenient to use a multistate trigger with specific patterns for each line.
#TR {Int: (%x)M ?(%d)? Wis: (%x)M ?(%d)? Str: (%x)M ?(%d)?} {
#ADDK StatCost {Int=%1|Wis=%3|Str=%5}
#ADDK StatValue {Int=%2|Wis=%4|Str=%6}
}
#COND {Con: (%x)M ?(%d)? Cha: (%x)M ?(%d)? Dex: (%x)M ?(%d)?} {
#ADDK StatCost {Con=%1|Cha=%3|Dex=%5}
#ADDK StatValue {Con=%2|Cha=%4|Dex=%6}
#VAR StatCheap {%case( %min( %t1, %t3, %t5, %t7, %t9, %t11), Int, Wis, Str, Con, Cha, Dex)}
#SHOW {Cheapest to train: @StatCheap, %db( @StatCost, @StatCheap), ~(%db( @StatValue, @StatCheap)~)}
}
This is written for command-line entry. If you prefer to use the Settings Editor, the Pattern is everything between the first set of braces (but not the braces themselves) and the Value is everything between the second set of braces (in bold red). The #COND is the second state (state 1) of the same trigger.
EDIT: Display routine needs more work |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|