Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Sharal
Newbie


Joined: 12 Nov 2006
Posts: 2

PostPosted: Sat Nov 03, 2007 5:43 pm   

Zmud Script help - skip lines?
 
Hi everyone,

I need a script to do some math calcuations for me. When I type Gold on Materia Magica, it displays the following...

Code:
Current holdings:
Bank Name                               Transf Rate   Withdr Rate   Your Balance
 New Rigel Bank and Trust               2.27%         2.36%         636,068 gp
 First Bank of Rune                     3.56%         3.55%         247,731 gp
*First Bank of Sigil                    2.64%         2.55%         1,243,836 gp
You have a total of [2,127,635] gp in 3 accounts, with [33,296] gp on hand.


I need to save the 'Your Balance' information, in the *First bank of Sigil... line, to a variable called startgold. I think if someone could tell me how to do that, I could probably handle the rest. I'm okay with single line triggers and aliases. I know there is a way to have the trigger skip lines and read info in from a specific number of lines later, but I can't find anything on how to do it. Please help.

Also, how do I read info in from between those brackets? I tried using the ~ quote character before the [ but it still won't read it in.

It's makin' me crazy.

Edit by Vijilante: added code tags to preserve spacing
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Nov 03, 2007 6:04 pm   
 
Use the %n wildcard to capture a number that's comma-spaced (it'll also handily strip out the commas for you). So your trigger will look something like:

#trig {^{ |~*}([%w ])%s(%d.%d)~% %s (%d.%d)~% %s (%n) gp} {#say Bank: %1;#say Transfer: %2 Withdraw: %3;#say Balance: %4}

Your trigger for the last line will look like:

#trig {You have a total of ~[(%n)~] gp in (%d) accounts, with ~[(%n)~] gp on hand.} {whatever}

You might need to apply the %float function to the numbers that're captured for the Transfer and Withdraw rates, because they might be captured as strings.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Nov 03, 2007 6:11 pm   
 
This should about do it. It is a little more then you wanted.
Code:
#CLASS Banking
#VAR BankAccounts {}
#VAR GoldTotal {}
#VAR GoldOnHand {}
#VAR StartGold {}
#TRIGGER "AccountCap" {^Current holdings:} {BankAccounts=""} {} {case|disable}
#COND {^({ |~*})(&39)%n~%%s%n~%%s(%n) gp} {#ADDKEY BankAccounts {%trim(%2)} {%3};#IF (%1="*") {StartGold=%2}} {looppat|param=10}
#TRIGGER "AccountEnd" {^You have a total of ~[%n~] gp in %d accounts, with ~[%n~] gp on hand.} {#STATE AccountCap 0;#T- AccountCap;GoldTotal=%1;GoldOnHand=%2;#T- AccountEnd}
#ALIAS gold {#T+ AccountCap;#T+ AccountEnd;~gold}
#CLASS 0
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Nov 03, 2007 6:19 pm   
 
Sorry Viji, but your pattern doesn't match. The trouble is that %n expands to the regex [+-]?[0-9,]+ and so AccountCap won't match the percentages. Your AccountEnd trigger doesn't have any captures, also.

It's a good demonstration of a way to use the patterns I gave above, though - it's one of the simplest ways to disable and enable the trigger based on the starting and ending lines of the text, and you might find that useful, Sharal.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net