Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Removing commas from trigger catches

Removing commas from trigger catches

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Silencher   (55 posts)  Bio
Date Wed 25 Mar 2015 05:58 AM (UTC)
Message
Hello.

I'm trying to make a trigger to save my bank balance because for some reason you can only see your bank balance inside the bank which disturbs me.

Here's the sample output:

Total Gold in Bank: 18,231

Below is my trigger:

<triggers>
<trigger
enabled="y"
group="Banker"
match="Total Gold in Bank: *"
send_to="12"
sequence="100"
>
<send>wealth = %1</send>
</trigger>
</triggers>


---------
The trigger only catches the '18' though and so I'm stuck as to what to do. I want to catch the whole 18,231, remove the comma, then store the 18231 number (Which will fluctuate of course) into that wealth variable. I have another simple alias that just notes that variable's contents.

How do I catch that? I'm assuming I need to use a regular expression but I'm not familiar with those.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 25 Mar 2015 08:44 AM (UTC)
Message

wealth = "%1"

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Silencher   (55 posts)  Bio
Date Reply #2 on Wed 25 Mar 2015 09:05 AM (UTC)
Message
That doesn't resolve my issue if I need to do arithmetic.

My desire is to make a trigger that totals my on-hand gold and my banked gold. Ordinarily I would just add 0 to the variable to convert it to a number, but that comma is still causing me to not catch the 2nd part of the gold amount.

It does allow me, of course, to see the string version, with the comma now though. But that's not really the overall goal.
Top

Posted by Fiendish   USA  (2,535 posts)  Bio   Global Moderator
Date Reply #3 on Wed 25 Mar 2015 07:01 PM (UTC)

Amended on Wed 25 Mar 2015 07:02 PM (UTC) by Fiendish

Message
wealth = tonumber(string.gsub("%1", ",", ""))

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Chyort   USA  (58 posts)  Bio
Date Reply #4 on Thu 26 Mar 2015 11:32 AM (UTC)
Message
You can use regular expressions, and a bit of creativity. Or take the easy road and use scripting.


But just FYI, this regular expression should work for you.

^Total Gold in Bank\: ((\d+)\,|)((\d+)\,|)(\d+) $


Should work for anything between 0 and 999,999,999

Then just wealth = "%2%4%5"


http://www.mushclient.com/mushclient/regexp.htm
For more info.
Top

Posted by Silencher   (55 posts)  Bio
Date Reply #5 on Fri 27 Mar 2015 03:07 AM (UTC)

Amended on Fri 27 Mar 2015 04:22 AM (UTC) by Silencher

Message
With the 'tonumber' example I get this error:
I get an error: bad argument #2 to 'tonumber' (base out of range)


And the regex solution doesn't even cause the trigger to fire. Does it matter that there are (varying) spaces between the : and the 1st number of the total gold?

UPDATE: I fixed the 'tonumber' example, it just needed another set of parenthesis. The regex solution still isn't firing, and I'm not sure why. The box for regular expressions is checked, of course.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #6 on Fri 27 Mar 2015 05:46 AM (UTC)
Message
Every space is important, but you can do something like this to skip one or more spaces:

\s+

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Chyort   USA  (58 posts)  Bio
Date Reply #7 on Fri 27 Mar 2015 09:02 AM (UTC)
Message
As nick said, spaces matter.

If his tip doesn't fix the problem i would look at the extra space at the end. It seemed odd to have one there but that is what your example had.


Total Gold in Bank:118,231 
Total Gold in Bank: 18,231 
Total Gold in Bank:  8,231 

If your output looks anything like this, then Nick's tip is the way to go.


Total Gold in Bank: 118,231
Total Gold in Bank: 18,231
Total Gold in Bank: 8,231

If it looks like this however. My guess is an extra space got added at the end. And needs to be removed.

(d+) $
(d+)$

for example.

Without more details it is hard to say though.
Top

Posted by Silencher   (55 posts)  Bio
Date Reply #8 on Fri 27 Mar 2015 12:50 PM (UTC)
Message
I just threw the \s+ before the string, after the : and after the # and that seemed to work. Both ways work, so that's great, thank you!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


27,022 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.