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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Tue Nov 15, 2011 1:55 am   

need help, Word Wrapping
 
I was trying to write a function with Zscript to word wrap but then i discovered the way i was writting it i would need like 4238904302 if checks to check for everything then i thought lua would be better to write it, then i remembered i dont know how to code lua, could someone help me out with a function that wraps a sentence at X chars please?
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Tue Nov 15, 2011 2:32 am   
 
The source of a function that will do what you want can be found here.

You will also need this auxiliary function.
_________________
Sic itur ad astra.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Nov 15, 2011 3:49 am   
 
What's your definition of sentence? Are we just talking basic alphanumerosymbolics (stuff you see printed on your keyboard, which you always want to see printed), or are you including the execution/handling of formatting control systems like ansi codes, mxp/xml/http tags, or color syntax codes across wrap boundaries?

If you are doing the former, you're only looking at like 10 lines at most:

Code:

#function MyWrap($column) {
  #switch (!%isnumber($column)) {#return "First argument is not a number."}
    (%null(%2)) {#return "No text to perform wrapping on."}
    (1) {
      #local $line $l
      $text = %replace(%-2," ","|")
      #forall $text {
        #if ((%len($l) + %len(%i) + 1) <= $column) {
          $l = %additem(%i,$l)
        } {
          $line = %additem(%replace($l,"|"," "),$line)%repeat(" ",($column - %len($l)))
          $l = %i
        }
      }
      $line = %additem(%replace($l,"|"," "),$line)%repeat(" ",($column - %len($l)))
      #return %expandlist($line,%cr)
    }
}


You can remove the %repeat() functions if you want, I put them in so that every line fills up the entire space to the wrap column.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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