|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Fri Sep 02, 2011 10:30 pm
trigger help with %format |
Ok trying to set up a couple triggers to capture how much gold I pick up, and get from selling at shops, and track currently carried gold, and stored gold in bank.
however part of my problem is I am having to deal with two formats of numerical values.
1234 and 1,234
this is my control trigger in case of bad captures or just to ensure correct values.
Coins | You are carrying 1,423 coins.
Code: |
#TR {Coins | You are carrying &cGold coins.} {} |
when picking up money. (this is the problem trigger... need to convert the control to a non-comma digit string, add the picked up amount, then reconvert back to the proper numerical)
You take 20 coins.
Code: |
#TR {^You take (%d) coins.} {#VA Gold = %format("&.0n",@cGold);#ADD Gold %format(&.0n,%1);#VA cGold %format("&.0n",@Gold)} |
It seems to work fine till I break 4 digits, then it starts at the lowest value IE 20, and adds to that number.
lets say I have 1,256 gold. I pick up 20. my display will change from 1,256 to 20 instead of 1,276 (1256+20)
thanks in advance.[/code] |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Sep 02, 2011 10:42 pm |
%d won't match numbers with commas in them, it just matches digits 0-9. You need to use %n instead. Also, instead of trying to convert back and forth to add, it would be much simpler to store it as a normal number without commas in your variable, then just format it with commas in your display.
|
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Sat Sep 03, 2011 12:44 pm |
Daern wrote: |
%d won't match numbers with commas in them, it just matches digits 0-9. You need to use %n instead. Also, instead of trying to convert back and forth to add, it would be much simpler to store it as a normal number without commas in your variable, then just format it with commas in your display. |
Nevermind, found a in-mud command that displays the info I need to track. was able to make simple triggers to capture that info to show in my #STW.
however I am curious if there is a means to make a trigger that ignores any number of extra spaces. party status layout for the mud has a large space between player name and HP/CP.
Instead of multiple triggers of the same thing +- a space for my guages, is there a way to make a single trigger ?
Code: |
^FL: &FLPlayer Hp: ~[&flhp/&flmaxhp~] Conc: ~[&flcp/&flmaxcp~] |
(this one captures a 3digit value for HP but a 4digit breaks it, as the HP is 1 space closer to player name.)[/code] |
|
|
|
geniusclown Magician
Joined: 23 Apr 2003 Posts: 358 Location: USA
|
Posted: Sat Sep 03, 2011 1:00 pm |
%s will match any number of spaces. So, you could have:
Code: |
^FL: &FLPlayer%sHp: ~[&flhp/&flmaxhp~] Conc: ~[&flcp/&flmaxcp~] |
Look up "pattern matching" and "predefined variables" in the help docs.
Also, using Regular Expressions to match is a bit more complex (and completely different syntax) but much, much more powerful (and more widely used), so you may want to look at that. |
|
_________________ .geniusclown |
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Wed Sep 07, 2011 2:01 pm |
I can't seem to get %format to work with a variable. works fine if I type the number into the code.
Code: |
Exp: 123,456,789
#show %format("&.0d",@Exp)
|
should have converted to 123456789, but all it prints is 0
EDIT: upon further examination I do not believe I am using the correct method, but at the same time I can not seem to find what I need to get it to do what I want. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed Sep 07, 2011 4:34 pm |
thats because you have told it effectively a length of 0 and 0 decimals.
i would suggest a higher length then the current one as well
#show %format("&12.0d",@Exp) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Wed Sep 07, 2011 4:46 pm |
that still shows a result of 0. considering that format uses , as a seperator. the variable in question gets expanded and %format reads up to the first , then ignores the rest.
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Sep 07, 2011 5:02 pm |
Why not do:
Code: |
#SHOW %replace(@Exp,",") |
instead? |
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Wed Sep 07, 2011 5:10 pm |
charneus wrote: |
Why not do:
Code: |
#SHOW %replace(@Exp,",") |
instead? |
*facepalm* knew it would be something simple... |
|
|
|
|
|