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
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Sat Aug 17, 2002 8:32 pm   

Removing Brackets
 
I have a file that I need to read in to zMUD using the #file command. The beginning of each line of that file has brackets containing text that I need to remove before showing the lines in zMUD. File looks like this:

[name of quest] Name of quest
[name of quest] Instructions
[name of quest] Instructions

I'd like it to display like:

Name of quest
Instructions
Instructions

There can be any number of lines for each quest entry, and I've already removed all other [] brackets and replaced them with parenthesis.

This is what I have so far:

#ALIAS quest
#FILE 2 script_quests.txt
#TYPE 2 "[name of quest]"
#FORALL @quest_matches {?}
#CLOSE 2

But I can't figure out how to strip off the []'s and the text between them.

Fat Tony
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Aug 17, 2002 9:41 pm   
 
You'll need to figure out how to loop through the file, but you can then use this line in the loop:

%replace(%read(2),"[name of quest] ", "")

li'l shmoe of Dragon's Gate MUD
Reply with quote
Thunderbuster
Novice


Joined: 07 Nov 2001
Posts: 45
Location: USA

PostPosted: Mon Aug 19, 2002 11:22 am   
 
Since Zmud doesn't have a %mid function try this

quest = [name of quest]
#MATH namelen %len(@quest)-1
quest = %left(@quest,namelen)
#MATH namelen %len(@quest)-1
quest = %right(@quest,namelen)

This will trim off any leading and ending character.

2nd place just means your a 1st place loser.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Aug 19, 2002 12:44 pm   
 
Instead of using #TYPE, try using %grep. %grep returns a stringlist with all the lines that match some text. Example:
#ALIAS quest {#FILE 2 script_quests.txt;#FORALL %grep(2, "^~[name of quest~]") {#SAY %copy(%i, %pos(%i, "]") + 2, %len(%i) - %pos(%i, "]") + 3)};#CLOSE 2}

Notice that %grep accepts a pattern. This is the reason why ^ can be used to match the beginning fo a line and why the brackets need to have the quote character before them.

Kjata
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