| View previous topic :: View next topic |
| Author |
Message |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sat Apr 22, 2006 3:35 pm Post subject: Read from .txt file... |
|
|
I've done a search, not got far.. i did find this so i tried to sort it out, but because i cant code TCL alot yet, it obviously it isnt working.
Any ideas? Would help alot
By The way, its to read from a file called sex.txt and to choose a random line on !sex to say into the #chan.
| Code: |
set sex "./sex.txt"
set sexmsg [string range [randomline $sex] 0 end]
bind pub - !sex randomline
proc randomline {nick uhost hand chan arg} {
# !sex triggers this procedure.
proc randomline { sex } {
set position [rand [expr [file size $filename] - 1024]]
set fd [open $filename r]
catch {
seek $fd $position
set text [read $fd 1024]
}
close $fd
set lines [split $text \n]
set lineno [randrange 1 [expr [llength $lines] - 1]]
return [lindex $lines $lineno]
}
}
|
_________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Last edited by DjBeNNeTT on Sat Apr 22, 2006 5:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sat Apr 22, 2006 4:18 pm Post subject: |
|
|
- you have pasted the code twice
- you define a proc within a proc
- you define two procs with the same name
- you unncessarily open the file twice (use gets twice, instead of read and second open)
- you define the random message globally... it will stay the same until rehash/restart
thats about all I can say about that code which will never work as itented like it is . _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sat Apr 22, 2006 5:45 pm Post subject: |
|
|
Well as i said, i know little. So i was wondering of some help.
Sorry for pasting twice, its now just once.
I had guessed that the 2 proc was wrong.. the first one was which causing the error.
Thanks for noticing tho's... Hope someone can point me in the right (coding) direction  _________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat Apr 22, 2006 6:05 pm Post subject: |
|
|
| Code: | set sex "./sex.txt"
bind pub - !sex sex:msg
proc sex:msg {nick uhost hand chan arg} {
global sex
set sexmsg [string range [randomline $sex] 0 end]
puthelp "privmsg $chan :$sexmsg"
}
proc randomline { filename } {
set position [rand [expr [file size $filename] - 1024]]
set fd [open $filename r]
catch {
seek $fd $position
set text [read $fd 1024]
}
close $fd
set lines [split $text \n]
set lineno [randrange 1 [expr [llength $lines] - 1]]
return [lindex $lines $lineno]
}
proc randrange { lowerbound upperbound } {
return [expr {int(($upperbound - $lowerbound + 1) * rand() + $lowerbound)}]
} |
_________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sat Apr 22, 2006 6:33 pm Post subject: |
|
|
Your a god for loads of stuff i want if this works!!!
Just the one prob i find atm...
on !sex...
[23:30:51] [BooByBoT] [22:30] Tcl error [sex:msg]: random limit must be greater than zero
I've changed both "set sexmsg [string range [randomline $sex] 0 end] " and "* rand()" to (3) and still nothing...
I'm turning blind (must be tired) lol _________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat Apr 22, 2006 7:27 pm Post subject: |
|
|
change:
| Code: | | set sex "./sex.txt" |
to
| Code: | | set sex "scripts/sex.txt" |
.. making certain the file (sex.txt) actually exists and you have added the lines of text you want (using pico).
I tested on a Windrop and it worked 100%.  _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sat Apr 22, 2006 7:39 pm Post subject: |
|
|
Mines windrop and Still getting same message...
my sex.txt file has: | Quote: | Ohhh babeh!
Hmmmm!
YES YES YEEESSHHHH!!!!
With You? [censored] off!
Send Me Your Pic First
Get Away From Me With That Filthy Anaconda! | All as it looks there..
What you mean "using pico"? _________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Apr 22, 2006 7:43 pm Post subject: |
|
|
| Code: | set sex "./sex.txt"
bind pub - !sex sex:msg
proc sex:msg {nick uhost hand chan arg} {
global sex
set sexmsg [string range [randomline $sex] 0 end]
puthelp "privmsg $chan :$sexmsg"
}
proc randomline f {
set data [split [read [set file [open $f]]][close $file] \n]
set position [rand [llength $data]]
lindex $data $position
} |
But the best solution would be to read the file into a list and use the list instead of the file everytime the command is called. Try to search the forum about how that can be implemented, it has been implemented 100 times here. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts
Last edited by Sir_Fz on Sat Apr 22, 2006 7:48 pm; edited 1 time in total |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat Apr 22, 2006 7:48 pm Post subject: |
|
|
Excellent Sir_Fz.
I concur. I should have thought of that in the first place.
| DjBeNNeTT wrote: | | What you mean "using pico"? |
pico is a *nix text editor. I was unaware you were using a Windrop in which case you'd be using notepad/EditPlus to edit scripts. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sat Apr 22, 2006 8:11 pm Post subject: |
|
|
Thank you both for your time. Sir_Fz worked perfectly! Thanks
And i actually use WordPad for scripts... as Notepad likes to bugger up most the time and not set out the next lines properly making it unreadable... Bugger thing.
Ah well
Thanks both again  _________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
Posted: Sun Apr 23, 2006 3:21 am Post subject: |
|
|
Thanks, i'll give it a try.
Is there a way that if it has $nick in the .txt file it will say the nickname who did the command? Or can that only be done in the code itself to say for each message?. _________________ DjBeNNeTT
Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Apr 23, 2006 4:40 am Post subject: |
|
|
use | Code: | | [subst -nocommands $sexmsg] |
instead of just $sexmsg. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
DjBeNNeTT Voice
Joined: 18 Feb 2006 Posts: 27 Location: Telford, Shropshire, UK
|
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
|