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
Arios26
Newbie


Joined: 04 Jul 2008
Posts: 4

PostPosted: Fri Jul 04, 2008 7:32 pm   

Adding to a variable from a txt file
 
Okay so I'm trying to add line 1 from a txt file to a variable. Then after my script does what it does, it goes to line 2 of the same txt file and adds that to a variable. How would I go about doing this?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jul 05, 2008 5:31 am   
 
to read in the data from your file into the variable, check out the %read() function. You can choose between #FORALL, #LOOP, and #WHILE/#UNTIL for your looping.
_________________
EDIT: I didn't like my old signature
Reply with quote
Arios26
Newbie


Joined: 04 Jul 2008
Posts: 4

PostPosted: Sat Jul 05, 2008 11:56 am   
 
Yeah I've read it and still not sure exactly how to get it working. I've tried it, but don't have much luck. Iwould do something like this?

#file 1 something.txt
#var whatever %read(1,1)

But not exactly sure ... it says something about 0 doing the sequential line ... that sounds like what I'd want..
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Sat Jul 05, 2008 3:53 pm   
 
You're going to need to loop it like he said.

But you'd do something like:
#FILE 1 something.txt
#LOOP %filesize(1) {#var whatever %read(1, %i)}

Obviously this is contrived. And just keeps resetting the whatever to each line of the file until file ends.

But I'm not sure where your #var assignment is in relation to the rest of the script. If it is all in an alias like this:

#ALIAS dork {
#var whatever blah
command1
command2
command3
}

Change it to this:

#ALIAS dork {
#LOOP %filesize(1)
#VAR whatever %read(1,%i)
command1
command2
command3
}
}
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Sat Jul 05, 2008 3:55 pm   
 
Or you could use 0, I never noticed that when using %read before. Course I didn't use it much either :)
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
Arios26
Newbie


Joined: 04 Jul 2008
Posts: 4

PostPosted: Sat Jul 05, 2008 4:35 pm   
 
Actually what I'm trying to do is make it pull it to a variable, intiate an alias, than pull the next line to that same variable replacing whats in it, initiate alias, etc til the file is empty.

So like:

pull to variable
do alias
pull next line to variable
do alias
pull next line to variable
do alias
etc etc etc.
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Sun Jul 06, 2008 5:07 pm   
 
So your way to initiate this could be:

#ALIAS dork {
#LOOP %filesize(1)
#VAR whatever %read(1,%i)
doalias
}
}
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
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