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
dysonsphere
Beginner


Joined: 11 Dec 2001
Posts: 16
Location: Canada

PostPosted: Fri Dec 14, 2001 2:13 am   

creating a string list from a file
 
Im trying to create a string list from a straight txt file

an example of the data in the file
Level 2:
armor 5 mana
detect invis 5 mana
ventriloquate 5 mana
Level 3:
invisibility 5 mana

what I want to do is as follows

for the spells at level 2 I want the string list to show up as
{armor|detectinvis|ventriloquate}

each lvl will have a seperate name and I need to strip off the mana costs
and any spaces in spell names
also spell names can be up to 3 words long

any ideas how I can go about this
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Fri Dec 14, 2001 6:22 am   
 
this should do the trick:


#ALIAS makeList {
#VAR line 1
#FILE 1 myBigListOfSpells.txt
#UNTIL (%read(1, @line) = %concat("Level ", %1, ":")) {
#ADD line 1
}
#WHILE (@record <> %concat("Level ", %eval(%1+1), ":")) {
#ADD line 1
#VAR record %read(1, @line)
#VAR spell ""
#LOOP %eval(%numwords(@record)-2) {
#VAR spell %concat(@spell, %word(@record, %i))
}
#ADDITEM spellList %replace(@spell, " ", "")
}
#CLOSE 1
}


Troubadour
Reply with quote
dysonsphere
Beginner


Joined: 11 Dec 2001
Posts: 16
Location: Canada

PostPosted: Fri Dec 14, 2001 6:55 am   
 
it didnt work, crashed zmud after a bit, I watch the @line var skyrocket over 65k


I forgot to mention that the level can jump a few

ie there is no level 1 line
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Dec 14, 2001 12:49 pm   
 
Only a few minor cxhanges. The lines with ; in front were changed or added. Make sure you use makelist with the level number your wish to capture ie "makelist 2".

ALIAS makeList {
#VAR line 1
#FILE 1 myBigListOfSpells.txt
#UNTIL (%read(1, @line) = %concat("Level ", %1, ":")) {
#ADD line 1
; #IF (@line > %filesize(1)) {
; #SHOW No Such Level in file.
; #CLOSE 1
; #ABORT 1
; }
}
; #WHILE (@line) {
#ADD line 1
#VAR record %read(1, @line)
; #IF (%word(@record,1)="Level") {
; #VAR line 0
; } {
#VAR spell ""
#LOOP %eval(%numwords(@record)-2) {
#VAR spell %concat(@spell, %word(@record, %i))
}
#ADDITEM spellList %replace(@spell, " ", "")
; }
}
#CLOSE 1
}
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