|
Cassie Newbie
Joined: 29 Oct 2006 Posts: 2
|
Posted: Sun Oct 29, 2006 3:20 am
Rookie Script Question (Triggers) |
I've tried to work this out for myself using the help manual, but I don't have a lot of experience using Zmud. Any help would be appreciated.
Essentially, a list of several items is displayed and from each line of that list I need to extract four variables.
List example:
Rapiers are sold in Grangier's for 25 gold pieces.
Daggers are sold in Meloria's for 98 silver pieces.
I composed a trigger of:
&Weapon are sold in &Loc for &%dPrice &Currency pieces.
For each weapon, I then need to check the price in a neighboring location and then perform a calculation to see if this is a better deal. That's just a single command (PRICE <thing> <location>) that would need to be entered for each weapon on the list.
In the above trigger I set it up to do PRICE @Weapon @Loc and it will do that for each weapon on the list (usually 20-30). I then set up a separate trigger that fires on the return of the price. I tried to just perform the calculation I need in this second trigger and output the result, but my @Weapon/@Loc/@Price/@Currency vars are set to the last item on the list so the calculation in the other trigger isn't coming out right.
I guess what I need to do is call a trigger within a trigger so my vars aren't overwritten...or read it line by line...or something. That's the part I'm lost on and couldn't work out from the help manual.
If anyone can help, I'd appreciate it.
-Cassie |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Sun Oct 29, 2006 10:13 pm |
Well, could you please give an example of the text before the list and the test after the list? Without your other triggers firing. Something like this
Health prompt
command you typed
everything the mud sent you
Health prompt |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Cassie Newbie
Joined: 29 Oct 2006 Posts: 2
|
Posted: Mon Oct 30, 2006 1:45 am |
I'm not entirely sure what you mean about the health prompt, but I'll go into more detail.
First, I type SHOW CATALOG
The mud returns a list that looks something like this:
Rapiers are sold in Grangier's for 25 gold pieces.
Daggers are sold in Meloria's for 98 silver pieces.
It's longer -- anywhere from between 10-30 items -- but you get the idea.
What I need to do with the list is then check the price of every item sold (rapier, dagger, etc.) in a neighboring city. The command for that is PRICE <thing> <location> (ie, PRICE RAPIERS DUNNEGARD) and a sneak is sent to check and report back (A shadow whispers, "Dunnegard is selling rapiers for 23 gold pieces.")
So, it would all look like this (with a short list, if typed out by hand using no triggers):
>SHOW CATALOG
>A weathered catalog reads:
> Rapiers are sold Grangier's for 25 gold pieces.
> Daggers are sold in Meloria's for 98 silver pieces.
>PRICE RAPIERS DUNNEGARD
>A shadow whispers, "Dunnegard is selling rapiers for 23 gold pieces."
>PRICE DAGGERS DUNNEGARD
>A shadow whispers, "Dunnegard is selling daggers for 112 silver pieces."
After the price is checked in the neighboring city, I need to mark it up by 4% (non-citizen tax) and then compare that price to the catalog price and output the result.
I tried to set this up with triggers, but can't get it to work. The variables remain set to the last item on the list, instead of cycling through line by line, pricing in Dunnegard and displaying the result.
I had one trigger at:
#TRIGGER {&Weapon are sold in &Loc for &%dPrice &Currency pieces.} {price @Weapon Dunnegard}
Then I had another trigger at:
#TRIGGER {A shadow whispers, "Dunnegard is selling rapiers for &%dDPrice &DCurrency pieces."} {did the calc, tried to compare to @Price and #SHOW the result}
That didn't work, so then I deleted what I had "coded" and tried to set the vars for each line into arrays, but I end up with blank entries until the last item on the list. It's like it's still just reading the last item in the catalog instead of each line.
For the arrays I set up an #ALIAS to initialize:
#VARIABLE WeaponsArray %array( Weapon)
#VARIABLE LocArray %array( Loc)
#VARIABLE PriceArray %array( Price)
#VARIABLE CurrencyArray %array( Currency)
#VARIABLE ArraySize 0
show catalog
The trigger stayed mostly the same:
#TRIGGER {&Weapon are sold in &Loc for &%dPrice &Currency pieces.}
#ADD ArraySize 1
#NOOP %arrset( WeaponsArray, @ArraySize, @Weapon)
#NOOP %arrset( LocArray, @ArraySize, @Loc)
#NOOP %arrset( PriceArray, @ArraySize, @Price)
#NOOP %arrset( CurrencyArray, @ArraySize, @Currency)
The output for one of the arrays ended up looking like this:
Currency "" "" "" "" "" "" 55
I'm just not sure how to make it work...heh, obviously. Hope that clarifies a little more what my problem is...thanks for any help anyone can give! |
|
|
|
darkspot Apprentice
Joined: 29 Jul 2002 Posts: 105
|
Posted: Mon Oct 30, 2006 9:14 pm |
This doesn't compare since I didn't want to make loads of vars, but a start is...
#var nCity {Dunnegard}
#trigger {(%w) are sold *'s for (%n) (%w) pieces.} {price %1 @nCity}
#trigger {(%w) is selling (%w) for (%n) (%w) pieces.} {#say {%1: %2 are %eval(%3 * 1.04) %4 pieces with tax.}}
This in theory (not tested) will do the following
>SHOW CATALOG
>A weathered catalog reads:
> Rapiers are sold Grangier's for 25 gold pieces.
price rapiers dunnegard
>A shadow whispers, "Dunnegard is selling rapiers for 23 gold pieces."
Dunnegard: rapiers are 23.9199981689453 gold pieces with tax.
> Daggers are sold in Meloria's for 98 silver pieces.
price daggers dunnegard
>A shadow whispers, "Dunnegard is selling daggers for 112 silver pieces."
Dunnegard: daggers are 116.479995727539 silver pieces with tax.
I didn't round it up or down since I didn't know how it functions, doing change with silver or what not.
Now this isn't a full setup yet, but I'm in class and gotta get going, I may take a few more steps later towards helping. |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Mon Oct 30, 2006 9:50 pm |
#TRIGGER {&Weapon are sold in &Loc for &%dPrice &Currency pieces.} {#addkey {WeaponList} {@Weapon} {@Price};price @Weapon Dunnegard}
#TRIGGER {A shadow whispers, "&TLoc is selling &Weapon for &%dPrice &TCurrency pieces."} {#math Price (@Price*1.04);#IF (@Currency = @TCurrency) {#IF (@WeaponList.@Weapon < @Price) {#SHOW @Weapon cheaper here!} {#SHOW @Weapon cheaper in @TLoc!}} {#SHOW Currency mismatch on @Weapon!!};#delkey {WeaponList} {@Weapon}}
Give that a whirl, it's not tested but ought to do the trick, make sure you delete your already existing 2nd trigger as the pattern I've put there is different, namely target location and target currency and there is no need for seperate weapon and price variables for the target location. |
|
_________________ Taz :) |
|
|
|
|
|
|
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
|
|