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.

this is not working why ?

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Thanhas
Op
Posts: 124
Joined: Sat Sep 02, 2006 11:14 am
Location: Ottawa, Canada

this is not working why ?

Post by Thanhas »

Code: Select all

set slap "./slap.txt" 
set slapmsg [string range [randomline $slap] 0 end] 

# Insert your own procedure. 

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] 
}

The Errors are...

Code: Select all

[06:28] Tcl error in file 'HosTer.conf':
[06:28] invalid command name "randomline"
    while executing
"randomline $slap"
    invoked from within
"string range [randomline $slap] 1 end"
    invoked from within
"set slapmsg [string range [randomline $slap] 1 end] "
    (file "scripts/slap.tcl" line 2)
    invoked from within
"source scripts/slap.tcl"
    (file "HosTer.conf" line 262)
[06:28] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You try to execute the proc randomline before you've created it..
NML_375
Post Reply