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


Joined: 10 Sep 2001
Posts: 6
Location: Sweden

PostPosted: Sat Feb 16, 2002 4:03 pm   

writing/reading problems
 
I have a problem:
On the MUD i play there are information.. Like when people die and such..
it looks like this: [INFO] Player was killed by mob. and so on..
Now I write it in to a file called info.txt and so far everything's cake.. But here comes the problem..
I want to be able to read the last 20 shows in that file..
But the %read or the #read commands doesnt support reading from the bottom of a document.. That means I have to fix it with the #write command instead.. So is there some way of writing at the start of a document instead of the bottom?

I would be really glad if someone could help me with this problem..

I am PathetiC
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Sat Feb 16, 2002 5:05 pm   
 
You're right, you can't directly tell the %read function to read the last 20 lines, but by using other functions, it can be done. Example:
#LOOP (%filesize(1)-20),(%filesize(1)) {#SH %read(1, %i)}

Kjata
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Sat Feb 16, 2002 5:18 pm   
 
Can you explain what the command does Kjata?

I realize it's looping, but how is it counting record numbers? or is it? I was just trying to figure a way for an alias to count the number of lines, then subtract then send the #READ command with the previous numbers.

Killing a fly on a friends forhead may not be overkill, use a hatchet to make sure the job is done.
Reply with quote
Agroamar
Beginner


Joined: 09 Feb 2002
Posts: 10
Location: USA

PostPosted: Sun Feb 17, 2002 7:07 am   
 
quote:
#LOOP (%filesize(1)-20),(%filesize(1)) {#SH %read(1, %i)}


Ok, This is what I see, first off, #LOOP takes range as its first argument, SO! %filesize(1), gets the number of lines in the file, which lets say its 100, So, the -20 sets the first range, to 80 (it subtracted 20), then the second range, is... 100, because its getting the TOTAL number of lines. The action that it does is show each line in turn that you started at, until you reached the last line. hrm, Hope that explains it.
Reply with quote
PathetiC
Newbie


Joined: 10 Sep 2001
Posts: 6
Location: Sweden

PostPosted: Sun Feb 17, 2002 1:07 pm   
 
quote:

quote:
#LOOP (%filesize(1)-20),(%filesize(1)) {#SH %read(1, %i)}


Ok, This is what I see, first off, #LOOP takes range as its first argument, SO! %filesize(1), gets the number of lines in the file, which lets say its 100, So, the -20 sets the first range, to 80 (it subtracted 20), then the second range, is... 100, because its getting the TOTAL number of lines. The action that it does is show each line in turn that you started at, until you reached the last line. hrm, Hope that explains it.





Thanx for that.. It works perfectly.. /PathetiC
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Sun Feb 17, 2002 1:08 pm   
 
Yup, what Agroamar said. It has the effect of reading the last 20 lines of a file, no matter how big the file is.

Kjata
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Sun Feb 17, 2002 2:07 pm   
 
Thanks Agroamar and Kjata.

It must have been too early. I never recongnized the filesize function. The explantion helps alot though. 'Precciate it.

Killing a fly on a friends forhead may not be overkill, use a hatchet to make sure the job is done.
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