|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Sun Feb 06, 2005 7:58 pm
Question regarding numbers |
How can I make zMUD make a number a certain fixed width?
I.E. if a trigger captures a variable that is only 1, how can I make it display
it as 01 ? (aside from capturing it as seperate characters, that just seems like
a hack and I'd like to avoid it) |
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Feb 06, 2005 10:37 pm |
I couldn't find a way to do this with a function, but check this out:
#ALIAS padleft {#IF (%numparam( ) >= 2) {#IF (%isnumber( %2)) {
pad.sourcetext = %1
pad.width = %2
#IF (%null( %3)) {pad.padchar = " "} {pad.padchar = %3}
pad.padtext = %concat( %repeat( @pad.padchar, %eval( @pad.width - %len( @pad.sourcetext))), @pad.sourcetext)
} {#MESSAGE "~[length~] must be a numerical value"}} {#MESSAGE "PADLEFT ~[text~] ~[length~] ~[pad char ~(optional~)~]"}}
#ALIAS padright {#IF (%numparam( ) >= 2) {#IF (%isnumber( %2)) {
pad.sourcetext = %1
pad.width = %2
#IF (%null( %3)) {pad.padchar = " "} {pad.padchar = %3}
pad.padtext = %concat( @pad.sourcetext, %repeat( @pad.padchar, %eval( @pad.width - %len( @pad.sourcetext))))
} {#MESSAGE "~[length~] must be a numerical value"}} {#MESSAGE "PADRIGHT ~[text~] ~[length~] ~[pad char ~(optional~)~]"}}
#ALIAS padcenter {#IF (%numparam( ) >= 2) {#IF (%isnumber( %2)) {
pad.sourcetext = %1
pad.width = %2
pad.padleft = %eval( (@pad.width - %len( @pad.sourcetext)) / 2)
pad.padright = %eval( @pad.width - (@pad.padleft + %len( @pad.sourcetext)))
#IF (%null( %3)) {pad.padchar = " "} {pad.padchar = %3}
pad.padtext = %concat( %repeat( @pad.padchar, @pad.padleft), @pad.sourcetext, %repeat( @pad.padchar, @pad.padright))
} {#MESSAGE "~[length~] must be a numerical value"}} {#MESSAGE "PADRIGHT ~[text~] ~[length~] ~[pad char ~(optional~)~]"}}
#VARIABLE pad {sourcetexttestpadtext00test000width9padchar0padleft2padright3} |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Mon Feb 07, 2005 2:27 am |
Simple Fixed width function You might be able to build upon this and its right off the top of my head
#FUNC fill {%repeat(%if(!%null(%3),%3,%char(32)),%eval(%2-%len("%1")))"%1"}
Example USAGE:
syntax: @fill(data, fil width, Optional fill char)
"data" is what to fill
"fill width" is amount of spaces to fill
"fill char" is char to fill with (default is an empty space)
Code: |
var=25
#SAY @fill(@var,10,0)
0000000025
|
Code: |
var=One
#SAY @fill(@var,10)
One
|
|
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Mon Feb 07, 2005 4:19 am |
Hrm.. i think I almost got it fixed.. just one small bump in the road.
zMUD output using #SHOW:
Code: |
.------------------------------------------------
| 1 | 11 | malefaction
| 1 | 7 | Blessed Gauntlets of the Templar
| 1 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
Ok, using this trigger:
#TRIGGER {^~| (%d) ~|} {#IF %1<10 {#PSUB %insert( 0, %1, 1) %x1} {}}
, I can get the first 1's to show as 01, thus ensuring that things will line up properly unless I go over 99 (which is not going to happen)
making my output look like this:
Code: |
.------------------------------------------------
| 01 | 11 | malefaction
| 01 | 7 | Blessed Gauntlets of the Templar
| 01 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
so I figure, great, I get the 1's to look like 01, I can just use the same trigger and this condition:
#COND {^~| (%d) ~| (%d) ~|} {#IF %2<10 {#PSUB %insert( 0, %2, 1) %x1} {}} {reparse}
to make the output make the 7 appear as 07
Obviously I was mistaken, as even though the second state says to work
with the second number, it still works with the first number in that line (but seems to mess with the first as well for some reason?) and my output looks like this:
Code: |
.------------------------------------------------
| 01 | 11 | malefaction
| 071 | 7 | Blessed Gauntlets of the Templar
| 01 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
Any ideas on how I could get that to work properly? |
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Mon Feb 07, 2005 4:24 am |
didn't see your post (as I had this open in another window and was trying to reply, just kept trying what I was going to reply so didn't get around to posting my reply till after dinner) but I will try that Nex. though simply getting the reparse condition of my trigger to work would accomplish what I mean to do.
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Feb 07, 2005 4:34 am |
Mumra wrote: |
didn't see your post (as I had this open in another window and was trying to reply, just kept trying what I was going to reply so didn't get around to posting my reply till after dinner) but I will try that Nex. though simply getting the reparse condition of my trigger to work would accomplish what I mean to do. |
You don't need a second condition, just put the second #if check in the first trigger |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Mon Feb 07, 2005 5:09 am |
Actually putting the condition in the first trigger accomplishes the same thing as doing it in the condition. i.e. making it say this:
Code: |
.------------------------------------------------
| 01 | 11 | malefaction
| 071 | 7 | Blessed Gauntlets of the Templar
| 01 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Mon Feb 07, 2005 5:18 am |
Hrm, odd, I just tried doing just the second part, i.e.
#TR {^~| (%d) ~|~ (%d) ~|} {#IF %2<10 {#PSUB %insert( 0, %2, 1) %x1} {}}
and the output from
Code: |
.------------------------------------------------
| 1 | 11 | malefaction
| 1 | 7 | Blessed Gauntlets of the Templar
| 1 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
turns out looking like this:
Code: |
.------------------------------------------------
| 1 | 11 | malefaction
| 07 | 7 | Blessed Gauntlets of the Templar
| 1 | 17 | Collar of Abyssal Servitude
'------------------------------------------------
|
It skipped the first line entirely, and went to the second, did the function on the WRONG variable, then skipped the third. hrm.. odd... (as 07 should be 1 and the 7 should be 07) |
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Mon Feb 07, 2005 5:45 am |
First a couple missing braces are obvious, Second the trigger above this is working correctly :P its taking the second number putting a 0 in front of it and sticking it in the %x1 spot (looks like you forgot to change something).
Reparse won't work correctly for #PSUB as the Orignal trigger line is checked not the already subbed line which will throw the %x variable off. However you can stack multiple psubs into one trigger.
#TR {^~| (%d) ~|~ (%d)~|} {
#IF %1<10 {#PSUB {%insert(0, %1, 1}} %x1}
#IF %2<10 {#PSUB {%insert( 0, %2, 1)} %x2}
} |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Mon Feb 07, 2005 8:21 pm |
Well Nex, that almost got it, a small brace problem in what you typed. but the 7 is turning into 077 now. But at least it is affecting the second digit partially correctly at least. but why it would turn into 077 I have no clue. (also, doing it as a condition with reparse turns out the same results, so I do think that because I specified a larger pattern, than it would take it into account properly)
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Feb 08, 2005 1:26 am |
A quick test should verify my thinking on this, but I can't be bothered. #PSUB is handled immediately. Hence when both conditions are true, the first #PSUB happens and inserts a 0. Then the line is at a different positioning and the second #PSUB happens. The current line is grabbed and the characters at the old position are replaced. Simply one more tweak at all is good. By reversing the order there will now problem with the %x1 and %x2 position becoming incorrect.
#TR {^~| (%d) ~|~ (%d)~|} {
#IF (%2<10) {#PSUB {%insert( 0, %2, 1)} %x2
#IF (%1<10) {#PSUB {%insert(0, %1, 1)} %x1
}
Includes the correction of Nexela's closing brace needing to be closing parenthesis, and addition of proper parenthesis around the condition argument of the #IFs. I likely would have made the same mistake the first time and very nearly did it again then rewrote things. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Tue Feb 08, 2005 3:36 am |
In the single trigger with multipe #PSUBS they can be in any order.
But there is a script that I wanted to have a reparse condition with a sub in the trigger and in the condition but I ran into position problems but I think your idea of doing it backwards might just be what I need so I will have to check that out.
And thanks for catching my typo but then you added two of your own, you forgot the closing braces after both %x's :P and I was also thinking that this might be a better rewrite if you don't want all kinds of zeros :P
#TR {^~| (%d) ~|~ (%d)~|} {
#PSUB {%format("&3.0e",%1)} %x1
#PSUB {%format("&3.0e",%2)} %x2
} |
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Tue Feb 08, 2005 3:48 am |
Vijilante's solution works, but here is another way of doing it since you know where the numbers are located:
#TR {^~| (%d) ~|~ (%d) ~|} {
#IF (%1<10) {#PSUB {0} 2 1}
#IF (%2<10) {#PSUB {0} 7 6}
} |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Tue Feb 08, 2005 1:45 pm |
Thanks everyone for the help, it is much appreciated, and you all rule :)
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
|
|