|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Sat Sep 19, 2009 4:18 am
Triggering on an unknown number of mostly identical lines |
So i'm trying to make a database for identification of items, and it's going ok until I realize that my mud adds "extra" abilities under the item as additional lines:
One item might have this many "Affects" lines:
Code: |
Object: mystical dragon sword Type: weapon
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Flags: glow owner magic anti-evil oiled
Weight: 20 Value: 80000 Level: 173
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Owner - Lasivian
Average Damage: 89
Condition: [perfect]
Proficiency: sword
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Affects saving-spell by -10
Affects saving-breath by -10
Affects saving-petri by -10
Affects saving-rod by -10
Affects saving-para by -10
Affects damroll by 35
Affects hitroll by 35
Affects hp by 200
Affects mana by 500
Affects ac by -40
Affects constitution by 2
Affects wisdom by 2
Affects intelligence by 2
Affects dexterity by 2
Affects strength by 2
Affects damroll by 11
Affects hitroll by 12
Hp:3548/3548(100%) Mn:3742/4051(92%) Mv:1264 G:9283706 Alt:100% (962930)
|
And another might have only one "Affects" line.
I can tell it it's done at the bottom with my prompt (As I included above), but I don't know how to tell it to expect 1, 5 or 17+ "Affects" lines before it knows it's done.
I'm guessing someone out there will know exactly how to solve this and i'm just missing it.
(And so we're all on the same page i've been using this tutorial: http://www.silverbridge.org/~varmel/zmud/tutorials/zmuddb.htm)
Thanks.
EDIT: If someone could show me how I could make sure this all falls into one database record with a single #TRIGGER that repeats on each "Affects" line that would work fine too. That's what I tried to do at first but I couldn't figure out how to incrementally increase a variable name to separate the different triggers. The worst part of this is some of the "Affects" repeat, so there might be 2 or even 3 identical lines that all need to be recorded. (I intend to allow duplicates in the database as well since similar equipment pops with different stats)
The only way I could think to do this was to make 20+ triggers each with a set number of affects lines closed with my prompt, but that seems pretty terrible codewise. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sat Sep 19, 2009 7:11 pm |
The common approach for this problem is to use two triggers, one of them a multi-state.
The first one will catch most of the identify info and then enable the trigger that matches all the 'Affects' lines. Tthe last state will disable the affects trigger (in your case it will be something that detects your prompt). The affects trigger will just keep matching and capture the variable data. The are some folks who prefer to use just one multistate trigger with the affects condition to be of trigger type
Loop Pattern.
The easiest way to make sure you it all falls in one database is to create a database variable that matches your eq database then use the #DBPUT command to save it. |
|
_________________ Asati di tempari! |
|
|
|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Sat Sep 19, 2009 7:43 pm |
Tech wrote: |
The common approach for this problem is to use two triggers, one of them a multi-state.
The first one will catch most of the identify info and then enable the trigger that matches all the 'Affects' lines. Tthe last state will disable the affects trigger (in your case it will be something that detects your prompt). The affects trigger will just keep matching and capture the variable data. The are some folks who prefer to use just one multistate trigger with the affects condition to be of trigger type
Loop Pattern.
The easiest way to make sure you it all falls in one database is to create a database variable that matches your eq database then use the #DBPUT command to save it. |
Ok, what i'm not understanding is how to make the affects trigger step forward for each new affects line.
#TRIGGER {Affects &affect} {}
Would just keep overwriting the same variable each time without realizing it had moved on to 2, 3, 4 (Sorry, you're probably assuming I know more than I do, heh) I can catch the info but I can't figure out how to write each affects to a different variable, or piece of a variable for that matter.
Right now i'm using a different variable for each piece of information, then doing a DB write when they are all filled. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Sep 19, 2009 8:31 pm |
Yes, that would overwrite the @affect variable. If you want to make it a stringlist, change &affect to (*), and then in the trigger code use the #additem command.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Sun Sep 20, 2009 12:27 am |
MattLofton wrote: |
Yes, that would overwrite the @affect variable. If you want to make it a stringlist, change &affect to (*), and then in the trigger code use the #additem command. |
Wouldn't that add a new database entry for each of the affects lines unless I made one trigger for the entire block of detected text? (This is something I have tried to do, but failed to accomplish) |
|
|
|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Sun Sep 20, 2009 2:07 am |
Ok, maybe let's try it this way, this is what I have so far (Echos are just for debugging):
Code: |
#CLASS {!_Item_Database}
#ALIAS id {#echo Capturing Item\#t+ !_Item_Database\#DBLOAD Item_Database.db\cast identify %1}
#TRIGGER {Object: &name Type: &type} {#echo Item Capture\#echo Name: @name Type: @type}
#TRIGGER {^Flags: &flags$} {#echo Flags- @flags}
#TRIGGER {^Weight: &weight Value: &value Level: &level$} {#echo Weight- @weight Value- @value Level- @level}
#TRIGGER {^Average Damage: &dmg$} {#echo Average Damage- @dmg}
#TRIGGER {^Affects &affectHp} {#echo Affects: @affect}
|
But I can't figure out how to handle things from there, can I get a simple example?
Thanks. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Sep 20, 2009 4:36 am |
Quote: |
Wouldn't that add a new database entry for each of the affects lines unless I made one trigger for the entire block of detected text? (This is something I have tried to do, but failed to accomplish)
|
#ADDITEM works only on stringlist variables. Stringlists are not datarecord variables. In ZMud, datarecord variables can have key fields that contain stringlists.
I missed that you could have repeated affects, so to handle that you need the %additem() function instead of the #additem command.
#trigger {^Affects (*)} {affects = %additem("%1",@affects)}
If you want to split the affects up into different recordable fields, it's probably easier to just make triggers to handle each type of affect rather than trying to parse out which field you need to fill in. This is where Tech's suggestion to use a multistate trigger that enables another trigger (in your case, it would be a class that contained all those Affects triggers) come into play.
Once you have the capture triggers worked out, in your prompt trigger or whatever will be the "I'm done" trigger, you would then use the #NEW command to add it to the database. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Sun Sep 20, 2009 4:48 am |
[quote="MattLofton"]
Quote: |
If you want to split the affects up into different recordable fields, it's probably easier to just make triggers to handle each type of affect rather than trying to parse out which field you need to fill in. This is where Tech's suggestion to use a multistate trigger that enables another trigger (in your case, it would be a class that contained all those Affects triggers) come into play.
Once you have the capture triggers worked out, in your prompt trigger or whatever will be the "I'm done" trigger, you would then use the #NEW command to add it to the database. |
The issue there is there are hundreds (The imm said probably 1000) of different affects, trying to make one trigger for each affect isn't really viable.
I would be happy to have all the affects in ONE recordable field in CSV format frankly. |
|
|
|
chris-74269 Magician
Joined: 23 Nov 2004 Posts: 364
|
Posted: Sun Sep 20, 2009 5:09 pm |
Make an alias to identify and add "say this is the end" to the end of it. Then you can trigger off that line you add to define the end of the affliction readout.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sun Sep 20, 2009 6:49 pm |
Or you can just use the prompt.
This is more along the lines of what I had in mind.
Code: |
#TRIGGER {Object: &name Type: &type} {#echo Item Capture;#echo Name: @name Type: @type}
#COND {^Flags: &flags$} {#echo Flags- @flags}
#COND {^Weight: &weight Value: &value Level: &level$} {#echo Weight- @weight Value- @value Level- @level}
#COND {^Average Damage: &dmg$} {#echo Average Damage- @dmg;#T+ Affects}
#COND {HP:} {#T- Affects}
#TRIGGER "Affects" {^Affects &stat by &amt} {#echo Affects: @Stat @Amt;#ADDKEY AffectList @Stat @Amt} "" {disable} |
|
|
_________________ Asati di tempari! |
|
|
|
Lasivian Wanderer
Joined: 25 Jan 2002 Posts: 76 Location: USA
|
Posted: Mon Sep 21, 2009 7:15 pm |
Awesome, that bit answers several of my questions and i've adapted it almost perfectly to my situation. You have my profuse thanks. (I'm one of those people that learns best by example)
Here is my code (It's kind of sloppy I admit but I don't like hidden parts of conditional triggers in the editor and any code I can understand and fix myself I consider good code Also note my setup uses the \ instead of ; for carriage return.):
Code: |
#ALIAS id {#DBLOAD Item_Database.db\cast identify %1} "!_Item_Database"
#TRIGGER {Object: &name Type: &type} {#echo IDB: Item Capture\#echo IDB: Name: @name Type: @type} "!_Item_Database"
#TRIGGER {^Flags: &flags$} {#echo IDB: Flags- @flags} "!_Item_Database"
#TRIGGER {^Weight: &weight Value: &value Level: &level$} {#echo IDB: Weight- @weight Value- @value Level- @level} "!_Item_Database"
#TRIGGER {^Armor Class: &dmg$} {#echo IDB: Armor Class- @AC\#T+ Affects} "!_Item_Database"
#TRIGGER {^Average Damage: &dmg$} {#echo IDB: Average Damage- @dmg\#T+ Affects} "!_Item_Database"
#TRIGGER {^Level &SpellLevel spells of: &Spells$} {#echo IDB: Spell Level- @SpellLevel Spells: @Spells\#Echo End of Pill/Potion, Recording\recorditem} "!_Item_Database"
#TRIGGER "Affects" {^Affects &stat by &amt} {#echo IDB: Affects: @Stat @Amt\#ADDKEY AffectList @Stat @Amt} "!_Item_Database" {disable}
#TRIGGER {HP:} {#T- Affects\#IF (@type != "") {#Echo IDB: End of Affects, Recording\recorditem} {#Echo Normal Prompt Line}} "!_Item_Database"
#ALIAS recorditem {#NEW @type Name=@name Type=@type Flags=@flags Weight=@weight Value=@value Level=@level Dmg=@dmg AC=@AC Affects=@AffectList SpellLevel=@SpellLevel Spells=@Spells\clearitemvars} "!_Item_Database"
#ALIAS clearitemvars {@name =""\@type =""\@flags =""\@weight =""\@value =""\@level =""\@dmg =""\@AC =""\@SpellLevel =""\@Spells =""} "!_Item_Database" |
One thing remains I cannot figure out, how do I write "AffectList" into a single text field in the database?
I found the "Database Variables" section of the help files, but I can't find any "Database variable to text string" command. It could probably be done with a DBLOOP to concat a string variable but that seems REAL sloppy. :)
Thanks again. |
|
|
|
|
|