Unknown2005-02-15 08:19:08
How can I create a custom function in zMUD which word-wraps a string to the specified number, e.g.
@wrap( string, wrap_length)
I think I might be able to do it... but I'm not sure if it's possible or not, and it will be pretty messy.
@wrap( string, wrap_length)
I think I might be able to do it... but I'm not sure if it's possible or not, and it will be pretty messy.
Daganev2005-02-15 08:21:36
You can use regular expressions to count the number of charachters on a line, and then use substiution to creat a NEWLINE marker in that string every number of chars.
However, you will have to test how that will affect your triggers.
However, you will have to test how that will affect your triggers.
Unknown2005-02-15 08:28:26
But I need it to wrap only on spaces and other punctuation, not in the middle of words.
I think you can do a bit of it using a mixture of %left, %numword and %word.
I think you can do a bit of it using a mixture of %left, %numword and %word.
Unknown2005-02-15 08:28:48
EDIT: %numwords
Daganev2005-02-15 08:51:10
I would do something like this.
Count 80 charachters, if 80th charachter is " |,|-|/n" make new line, else go to next char.
Count 80 charachters, if 80th charachter is " |,|-|/n" make new line, else go to next char.
Unknown2005-02-15 08:59:21
Yuck... Then if you have a really long word which starts at the 79th column, it would extend far over where you want to actually wrap.
With the part-script I made with %left, %numwords, and %word, I can't get the correct wrap (80 or less) for the first line and retrieve that line as a string. What I need it to be able to do it until there is nothing left to wrap and storing everything in variables, using %exec( #LOOP...) or something. The only problem with #LOOP and #FORALL is that, when displayed in the Status Window, flickers. %repeat needs to be able to be used with %i.
With the part-script I made with %left, %numwords, and %word, I can't get the correct wrap (80 or less) for the first line and retrieve that line as a string. What I need it to be able to do it until there is nothing left to wrap and storing everything in variables, using %exec( #LOOP...) or something. The only problem with #LOOP and #FORALL is that, when displayed in the Status Window, flickers. %repeat needs to be able to be used with %i.

Daganev2005-02-15 09:27:09
flickering is do to something else....
YOu might want to change a refresh setting.
YOu might want to change a refresh setting.
Unknown2005-02-16 03:07:23
No, flickering occurs if you have a loop command (e.g. #LOOP or #FORALL) in the Status Window. This is due to that it continuously updates the window, repeating the loop until it is removed entirely from the window. It doesn't do this in the main window(s), because it just adds it to the window once and leaves it. It's basically like having an alarm like this:
It may not flicker on faster computers though, if they can redisplay it fast enough not to flicker. (My PC is 600MHz.)
Could you please post an example of how this regular expression script could work. I'm guessing it'd use %regex...
I'll post an example of my script which uses %left, %numwords, and %word -- if I can re-create/find it (I'm not sure which world I created it in).
CODE
#ALARM {0.1} {#CLR;#LOOP 20 {#SHOW Blah. Blah. Blah. Blah. Blah. Blah. Blah.}
It may not flicker on faster computers though, if they can redisplay it fast enough not to flicker. (My PC is 600MHz.)
Could you please post an example of how this regular expression script could work. I'm guessing it'd use %regex...
I'll post an example of my script which uses %left, %numwords, and %word -- if I can re-create/find it (I'm not sure which world I created it in).
Unknown2005-02-17 05:39:07
Surely someone knows how a wrapping system would work... Even if they don't know zMUD, just a brief explanation of what a wrapping script in another language functions; not the actual code, just what it does. For example, someone who's coded MUDs would know how their wrapping system works.
Daganev2005-02-17 05:43:50
You brought up a good point with a word starting on the 79th charachter so I had to rethink it.
Do a charcount of say 60 or 65 (you'll have to play with it) Then do a search for a word, and say go to end of word. (excel does this, so I'm sure other programs can to) Then set a new line.
I think to make it work you have to capture the whole line into a trigger that stores it as a variable. You then do the script to the variable in an alias maybe, which then spits out the variable using Substitute. If that doesn't work try a GAG and SAY method.
Do a charcount of say 60 or 65 (you'll have to play with it) Then do a search for a word, and say go to end of word. (excel does this, so I'm sure other programs can to) Then set a new line.
I think to make it work you have to capture the whole line into a trigger that stores it as a variable. You then do the script to the variable in an alias maybe, which then spits out the variable using Substitute. If that doesn't work try a GAG and SAY method.
Unknown2005-02-17 05:48:22
That would be alright... if zMUD didn't actually show gagged lines before it gags them. An alias, or somehow set a trigger, maybe, would probably be better... Although the show and gag thing would be able to be coded neater.
I'll try asking on a MUD of which I am a builder on. Because there, when I am creating room descs, I can do "*f" to format and wrap it. Maybe a coder there could tell me how that works...
I'll try asking on a MUD of which I am a builder on. Because there, when I am creating room descs, I can do "*f" to format and wrap it. Maybe a coder there could tell me how that works...
Daganev2005-02-17 06:05:45
I don't think Zmud does tokens or tokenizers, but most programing langauges do.
Oh, and I have this thirdeye script that sucessfully GAGs the entire WHO list and only shows me the name I'm looking for without spammed blank lines. So I don't think you will have a problem with Zmud showing you the text before you gag it.
I'm assuming your using version 7. if your not, I could be more wrong than I might allready be.
Oh, and I have this thirdeye script that sucessfully GAGs the entire WHO list and only shows me the name I'm looking for without spammed blank lines. So I don't think you will have a problem with Zmud showing you the text before you gag it.
I'm assuming your using version 7. if your not, I could be more wrong than I might allready be.
Unknown2005-02-17 08:05:11
I do use version 7. 
Okay, I created a script based off a bit of what you said, but it's still far from perfect...
But it displays
as
...And I'm not sure exatly how to fix that.
Also, how can I get the newline function (%crlf) to stay as "%crlf" when it is still in the variable (then when it is echoed, it can transform it to an actual new line)? Even when I put it as ""%{crlf}"" in the wrap_next alias, when it does #VARIABLE Wrap_Done {@Wrap_Done...}, it changes to the %crlf to a newline each time -- I want to keep it as the function until it is shown/returned.

Okay, I created a script based off a bit of what you said, but it's still far from perfect...
CODE
#CLASS {Wrapping}
#ALIAS wrap_function {#VARIABLE Wrap_ToDo %1;#VARIABLE Wrap_Done %null;#IF (%isnumber( %2)) {#VARIABLE Wrap_At %2} {#VARIABLE Wrap_At 80};wrap_next;#ECHO @Wrap_Done}
#ALIAS wrap_next {#VARIABLE Wrap_Current {%left( @Wrap_ToDo, %eval( @Wrap_At - 10))%if( !%ends( %left( @Wrap_ToDo, %eval( @Wrap_At - 10)), " "), " ")%word( %right( {%1}, %eval( @Wrap_At - 10)), 1)};#VARIABLE Wrap_ToDo {%right( @Wrap_ToDo, %len( @Wrap_Current))};#VARIABLE Wrap_Done {@Wrap_Done%if( @Wrap_Done != %null, "%{crlf}")%trim( @Wrap_Current)};#IF (@Wrap_ToDo != %null) {wrap_next}}
#VAR wrap {%exec( "wrap_function "%1" "%2"")}
#VAR Wrap_Current {}
#VAR Wrap_ToDo {}
#VAR Wrap_Done {}
#CLASS 0
#ALIAS wrap_function {#VARIABLE Wrap_ToDo %1;#VARIABLE Wrap_Done %null;#IF (%isnumber( %2)) {#VARIABLE Wrap_At %2} {#VARIABLE Wrap_At 80};wrap_next;#ECHO @Wrap_Done}
#ALIAS wrap_next {#VARIABLE Wrap_Current {%left( @Wrap_ToDo, %eval( @Wrap_At - 10))%if( !%ends( %left( @Wrap_ToDo, %eval( @Wrap_At - 10)), " "), " ")%word( %right( {%1}, %eval( @Wrap_At - 10)), 1)};#VARIABLE Wrap_ToDo {%right( @Wrap_ToDo, %len( @Wrap_Current))};#VARIABLE Wrap_Done {@Wrap_Done%if( @Wrap_Done != %null, "%{crlf}")%trim( @Wrap_Current)};#IF (@Wrap_ToDo != %null) {wrap_next}}
#VAR wrap {%exec( "wrap_function "%1" "%2"")}
#VAR Wrap_Current {}
#VAR Wrap_ToDo {}
#VAR Wrap_Done {}
#CLASS 0
But it displays
QUOTE
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg.
as
QUOTE
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blah
. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bla
g. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bl
hg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah b
ahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bla
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bl
h blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. B
ah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg.
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blah
. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bla
g. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bl
hg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah b
ahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bla
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bl
h blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. B
ah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg.
Blah blahg. Blah blahg. Blah blahg. Blah blahg.
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blah
. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bla
g. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bl
hg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah b
ahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bla
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bl
h blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. B
ah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg.
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg
Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blah
. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bla
g. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah bl
hg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah b
ahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bla
blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Bl
h blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. B
ah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg. Blah blahg.
Blah blahg. Blah blahg. Blah blahg. Blah blahg.
...And I'm not sure exatly how to fix that.
Also, how can I get the newline function (%crlf) to stay as "%crlf" when it is still in the variable (then when it is echoed, it can transform it to an actual new line)? Even when I put it as ""%{crlf}"" in the wrap_next alias, when it does #VARIABLE Wrap_Done {@Wrap_Done...}, it changes to the %crlf to a newline each time -- I want to keep it as the function until it is shown/returned.
Daganev2005-02-17 08:12:40
It appears to be replacing the last charachter on the line with the new line function. If you notice, the last charachter on each line is Missing.
For example it says "blah /n ." instead of "blah /n g."
To be honest, I can't follow your code in the format its in. I need proper spaces and stuff. I'm a very low level programer who is used to very high level languages.
Second, I'm curious as to why its making new lines in the middle of words.
For example it says "blah /n ." instead of "blah /n g."
To be honest, I can't follow your code in the format its in. I need proper spaces and stuff. I'm a very low level programer who is used to very high level languages.

Second, I'm curious as to why its making new lines in the middle of words.
Unknown2005-02-17 08:21:19
QUOTE(daganev @ Feb 17 2005, 09:12 PM)
Second, I'm curious as to why its making new lines in the middle of words.
52754
I'm curious too.

QUOTE(daganev @ Feb 17 2005, 09:12 PM)
It appears to be replacing the last charachter on the line with the new line function. If you notice, the last charachter on each line is Missing.
For example it says "blah /n ." instead of "blah /n g."
To be honest, I can't follow your code in the format its in. I need proper spaces and stuff. I'm a very low level programer who is used to very high level languages.Â
For example it says "blah /n ." instead of "blah /n g."
To be honest, I can't follow your code in the format its in. I need proper spaces and stuff. I'm a very low level programer who is used to very high level languages.Â

52754
Characters, not charachters!
Stupid zMUD syntax thing made it so it doesn't change the semi-colons to new lines in the script window, so I'll re-format it manaully:
CODE
#CLASS {Functions|Wrapping}
#ALIAS wrap_function {
 #VARIABLE Wrap_ToDo %1
 #VARIABLE Wrap_Done %null
 #IF (%isnumber( %2)) {#VARIABLE Wrap_At %2} {#VARIABLE Wrap_At 80}
 wrap_next
 #ECHO @Wrap_Done
 }
#ALIAS wrap_next {
 #VARIABLE Wrap_Current {%left( @Wrap_ToDo, %eval( @Wrap_At - 10))%if( !%ends( %left( @Wrap_ToDo, %eval( @Wrap_At - 10)), " "), " ")%word( %right( {%1}, %eval( @Wrap_At - 10)), 1)}
 #VARIABLE Wrap_ToDo {%right( @Wrap_ToDo, %len( @Wrap_Current))}
 #VARIABLE Wrap_Done {@Wrap_Done%if( @Wrap_Done != %null, %crlf)%trim( @Wrap_Current)}
 #IF (@Wrap_ToDo != %null) {wrap_next}
 }
#VARIABLE wrap {%exec( "wrap_function "%1" "%2"")}
#VARIABLE Wrap_Current {}
#VARIABLE Wrap_ToDo {}
#VARIABLE Wrap_Done {}
#CLASS 0
#ALIAS wrap_function {
 #VARIABLE Wrap_ToDo %1
 #VARIABLE Wrap_Done %null
 #IF (%isnumber( %2)) {#VARIABLE Wrap_At %2} {#VARIABLE Wrap_At 80}
 wrap_next
 #ECHO @Wrap_Done
 }
#ALIAS wrap_next {
 #VARIABLE Wrap_Current {%left( @Wrap_ToDo, %eval( @Wrap_At - 10))%if( !%ends( %left( @Wrap_ToDo, %eval( @Wrap_At - 10)), " "), " ")%word( %right( {%1}, %eval( @Wrap_At - 10)), 1)}
 #VARIABLE Wrap_ToDo {%right( @Wrap_ToDo, %len( @Wrap_Current))}
 #VARIABLE Wrap_Done {@Wrap_Done%if( @Wrap_Done != %null, %crlf)%trim( @Wrap_Current)}
 #IF (@Wrap_ToDo != %null) {wrap_next}
 }
#VARIABLE wrap {%exec( "wrap_function "%1" "%2"")}
#VARIABLE Wrap_Current {}
#VARIABLE Wrap_ToDo {}
#VARIABLE Wrap_Done {}
#CLASS 0
Is that better? All the functions are annoying to read and write, as you have to follow each one...
Daganev2005-02-17 08:27:16
What's the syntax of what you write in?
i.e
You do wrapfunction 1 80 or what?
Also, can you check to see if there is a " "(ie. SPACE) at the end of each line? I think it might be replacing the last char with a SPACE instead of a just adding a Newline.
i.e
You do wrapfunction 1 80 or what?
Also, can you check to see if there is a " "(ie. SPACE) at the end of each line? I think it might be replacing the last char with a SPACE instead of a just adding a Newline.
Daganev2005-02-17 08:30:17
To explain myself so you don't miss it while writing a responce.
I think you code takes the last char of the line (i.e char count 80). turns it into a " " and then replaces the " " with a /n.
oh, and I never knew you could put so much code stored into a variable!
I think you code takes the last char of the line (i.e char count 80). turns it into a " " and then replaces the " " with a /n.
oh, and I never knew you could put so much code stored into a variable!
Unknown2005-02-17 08:31:08
You do this:
@wrap( "string_to_wrap", wrap_at_number)
And the wrap_at_number value is optional -- it defaults to 80.
(In your command line, you may have to add < and > around it.
Alternatively, you can do the alias:
wrap_function "string" xx
But I put it into a variable/function thing so I can use it with scripts better.)
@wrap( "string_to_wrap", wrap_at_number)
And the wrap_at_number value is optional -- it defaults to 80.
(In your command line, you may have to add < and > around it.
Alternatively, you can do the alias:
wrap_function "string" xx
But I put it into a variable/function thing so I can use it with scripts better.)
Unknown2005-02-17 08:32:26
Oh, and I think the missing character problem comes with using %left/right, I'll have to change one by 1.
Daganev2005-02-17 08:33:56
Ok I see the problem then. Your counting 10 chars back from the 80. but once you hit the char your not moving foward to the right side of the next word.