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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Tievel
Newbie


Joined: 16 Oct 2005
Posts: 7

PostPosted: Mon Mar 26, 2007 6:10 am   

Capturing Blank Lines to a Variable
 
Hello,

I am currently creating a program that stores news posts into a database. Right now what I'm doing is capturing the multi-line news posts into a variable and updating the respective field in the database with the variable text. This works fine, but if possible I would like to maintain the formatting one sees when reading the news post in the MUD. As such I've reached my wit's end trying to figure out how to capture a blank line into a variable in order to maintain the paragraph spacing and whatnot. Any suggestions would be greatly appreciated, and if this is too vague I'll be happy to provide more details.

Thanks in advance,
Tievel
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Mar 26, 2007 6:59 am   
 
Well, there are a couple of ways of doing it depending on how you're printing the news posts afterwards. And what kind of database you're using to store the posts. If you're using a stringlist for example and running through each item #saying them, you could add an item %cr to the list, or an item "". It really depends on exactly how your script works.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Josiah.Bruns
Apprentice


Joined: 04 Mar 2007
Posts: 103

PostPosted: Mon Mar 26, 2007 10:38 pm   
 
is there away to trigger on cr or a lf? i would be interested in writing a trigger to replace a cr with the red text cr then the real cr and so on. to help me understand how the mudd and zmud are dealing with these items. currently i have a script doing a very similar thing as tievel mentioned above, i am capturing %line's using concat to add them to a var and for some reason the blank lines do not seem to get added to the var.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Mar 27, 2007 12:32 am   
 
I think this is what you want.

Code:
#VAR variable {} {}
#REGEX {\n} {#var variable %concat( @variable, %line, %lf);#col 12}
#TRIGGER {^$} {#var variable %concat( @variable, %lf)}


Keep in mind that when you are displaying the contents of the variable you want to use #showP or #sayP.
So.
#ShowP @variable

Also, and very important when you are not using these triggers you need to TURN THEM OFF. If they are left on they will continuously eat up memory and keep a log of everything that has happened on the mud inside the variable. It is also a good idea to TURN OFF the triggers if you are displaying the contents of the variable. Think INFINITE LOOP.

Finally if you intend to reproduce this for OTHER people that you will want to put something besides %lf.

Edit: and for replacing it with a red CR you could do %concat(@variable,%ansi(red)cr%ansi(green))
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Tievel
Newbie


Joined: 16 Oct 2005
Posts: 7

PostPosted: Tue Mar 27, 2007 3:40 am   
 
First of all, thank you for the responses.

The code above seemingly did the trick of capturing the blank lines into variables, but I'm still running into the problem of maintaining the formatting when it goes into the database with #VAR databasers("PostText").Value @Variable

Thank you again for the help and sorry to be a bother.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Mar 27, 2007 4:02 am   
 
Try this instead.
#VAR databasers("PostText").Value {(@Variable)}
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Tievel
Newbie


Joined: 16 Oct 2005
Posts: 7

PostPosted: Thu Mar 29, 2007 4:00 am   
 
First of all, thank you again for the help.

Unfortunately it still isn't working. I've pretty much given up on the idea of maintaining formatting inside the zmud variable. What I'm thinking of trying next is to insert some sort of marker and then have an external program go through the database and reformat the text. Thoughts?
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Mar 29, 2007 4:59 am   
 
Ah, the external program explains it not working. I don't use external programs with cmud/zmud so I assumed you were using internal commands somehow!

Instead of using %lf you could use "mynewline" or some other string then turn around in the external program and use its replace function to put in the newlines. If you already know a command for the external program to make a newline then you could use THAT command. An example would be to use a <br> for HTML.

#TRIGGER {^$} {#var variable %concat( @variable, "<br>")}
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Tievel
Newbie


Joined: 16 Oct 2005
Posts: 7

PostPosted: Thu Mar 29, 2007 5:28 am   
 
Thank you for all your help, Arminas. I will do just that.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Mar 30, 2007 7:47 am   
 
Is it possible that the reason you're not getting the right formatting is that you're adding only linefeed %lf, or only carriage return %cr to the end of the line?
Don't must programs on Windows see a newline as a carriage return and a linefeed?
Try terminating the line with %{cr}%{lf} and see if that makes a difference.

Anyways here's hoping Smile.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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