This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Reading from a file.

Old posts that have not been replied to for several years.
Locked
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Reading from a file.

Post by ^DooM^ »

Hello again im having trouble reading from a flat file on my shell.

Well i can read it but i cant display its contents in channel.

It's based on a quote script by Koloth, v1.0. i altered it so people could add quake servers to it for people to play on. and remove them if they are down. it currently displays how many servers are added and it will pull a random server (Was a random quote) from the list with !server (which used to be !quote) so everything works fine. now instead of having a random server displayed on channel id like it to reel off the entire list. can someone give me an example of how display a document on channel. I have already opened the file, read the contents and closed it again.

Thanks in advance. :wink:

^DooM^
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Re: Reading from a file.

Post by strikelight »

^DooM^ wrote:Hello again im having trouble reading from a flat file on my shell.

Well i can read it but i cant display its contents in channel.

It's based on a quote script by Koloth, v1.0. i altered it so people could add quake servers to it for people to play on. and remove them if they are down. it currently displays how many servers are added and it will pull a random server (Was a random quote) from the list with !server (which used to be !quote) so everything works fine. now instead of having a random server displayed on channel id like it to reel off the entire list. can someone give me an example of how display a document on channel. I have already opened the file, read the contents and closed it again.

Thanks in advance. :wink:

^DooM^
if you have read the contents into a variable, then it is a simple matter of regular variable manipulation...

For example..

Code: Select all

foreach line [split $your_data_variable \n] {
  puthelp "PRIVMSG $chan :$line"
}

(or if you've already created a _list_ from the file):

foreach element $your_data_list {
  puthelp "PRIVMSG $chan :$element"
}
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Thanks for your prompt reply m8 much appreciated :wink:

im sure im doing it right but i get this error now.
[23:17] Tcl error [qot_all]: can't read "qot_list": variable is array
any ideas?
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

^DooM^ wrote:Thanks for your prompt reply m8 much appreciated :wink:

im sure im doing it right but i get this error now.
[23:17] Tcl error [qot_all]: can't read "qot_list": variable is array
any ideas?
well, the error message means that TCL is sure you aren't doing it right... :wink:

I'm not sure how you are creating the variable qot_list, but somehow you are creating it as an array... You'll need to show that.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

ok here is the code i botched together. :roll:

Code: Select all

proc qot_all {nick uhost hand chan rest} {

global qot
    if {![file exists $qot(file)]} {
	putchan $chan "Error: No Servers found or database does not exist"
	return
    }
    set qot_fd [open $qot(file) r]
    for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } {
	gets $qot_fd qot_list($qot_cnt)
    }
    close $qot_fd
    set qot_cnt [expr $qot_cnt - 2]
    unset qot_list([expr $qot_cnt + 1])
    if {![info exists qot_list([expr $rest - 1])]} {
	putchan $chan "Error: that server does not exist"
	return
    } else {
    foreach line [split $qot_list \n] { 
    putchan $chan "[expr $qot_cnt + 1] Servers in total"
    putchan "PRIVMSG $chan :$line" 
    return
    }
  }
}
Thanks strikelight :wink:
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

^DooM^ wrote:ok here is the code i botched together. :roll:

Code: Select all

proc qot_all {nick uhost hand chan rest} {

global qot
    if {![file exists $qot(file)]} {
	putchan $chan "Error: No Servers found or database does not exist"
	return
    }
    set qot_fd [open $qot(file) r]
    for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } {
	gets $qot_fd qot_list($qot_cnt)
    }
    close $qot_fd
    set qot_cnt [expr $qot_cnt - 2]
    unset qot_list([expr $qot_cnt + 1])
    if {![info exists qot_list([expr $rest - 1])]} {
	putchan $chan "Error: that server does not exist"
	return
    } else {
    foreach line [split $qot_list \n] { 
    putchan $chan "[expr $qot_cnt + 1] Servers in total"
    putchan "PRIVMSG $chan :$line" 
    return
    }
  }
}
Thanks strikelight :wink:
Ok, so instead of a list, you have created an array...

I believe you'll want to change:

Code: Select all

    } else {
    foreach line [split $qot_list \n] { 
      putchan $chan "[expr $qot_cnt + 1] Servers in total"
      putchan "PRIVMSG $chan :$line" 
      return
    }
To the following:

Code: Select all

   } else {
    putchan $chan "[expr $qot_cnt + 1] Servers in total"
    foreach id [array names qot_list] { 
      putchan $chan "$qot_list($id)" 
    }
   }
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

thanks m8 Works a treat :wink: :wink: :wink:
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
Locked