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.

help please[solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

help please[solved]

Post by blake »

Hey can someone help with this code i keep getting errors when i try starting my eggie

also when i do the command !next i have to put the lnie number is it possible to just do !next without line number so it will read each line seperate this used to work but has been messed up somewere

Code: Select all

[15:49] Tcl error in file 'eggdrop.conf':
[15:49] missing close-brace
    while executing
"proc next_proc { nick uhost hand chan arg } { 
global out_chan txt_file 

set line [lindex [split $arg] 0] 
if {$line == ""} { 
putserv "PRIVMSG $chan..."
    (file "scripts/training.tcl" line 6)
    invoked from within
"source scripts/training.tcl"
    (file "eggdrop.conf" line 1332)
[15:49] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)

Code: Select all

set out_chan "#Trainingroom" 
set txt_file "Training.txt" 
bind pub SA|SA !next next_proc 
bind pub SA|SA !back back_proc 

proc next_proc { nick uhost hand chan arg } { 
   global out_chan txt_file 
   set line [lindex [split $arg] 0] 
   if {$line == ""} { 
   putserv "PRIVMSG $chan :Usage: !next <linenumber>" 
   return 
   } 
   set take_me [open $txt_file r] 
   set take_all [split [read $take_me] "\n"] 
   close $take_me 
   }
   foreach txt_line $take_all { 
   if {$txt_line != ""} { 
   putquick "PRIVMSG $out_chan :$txt_line" 
   }
}

proc back_proc { nick uhost hand chan arg } { 
   global out_chan txt_file 
   set line [lindex [split $arg] 0] 
   if {$line == ""} { 
   putserv "PRIVMSG $chan :Usage: !back <line number>" 
   return 
   } 
   set take_me [open $txt_file r] 
   set take_all [split [read $take_me] "\n"] 
   close $take_me 
   set data [lindex $take_all [expr $line - 1]] 
   putquick "PRIVMSG $out_chan :$data" 
   }
} 
Last edited by blake on Thu Dec 17, 2009 3:51 pm, edited 3 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You've got a few unbalanced braces in there..
Indent the code properly, and it should be alot simpler to see where they're missing..
NML_375
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

nml375 wrote:You've got a few unbalanced braces in there..
Indent the code properly, and it should be alot simpler to see where they're missing..
I`ve put it back to how I think it should have been unfortunetly the original script I had was on computer that went bang
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If I were to properly indent your last code snippet, it would look like this:

Code: Select all

set out_chan "#Trainingroom"
set txt_file "Training.txt"
bind pub SA|SA !next next_proc
bind pub SA|SA !back back_proc

proc next_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !next <linenumber>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
}
foreach txt_line $take_all {
  if {$txt_line != ""} {
    putquick "PRIVMSG $out_chan :$txt_line"
  }
}

proc back_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !back <line number>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  set data [lindex $take_all [expr $line - 1]]
  putquick "PRIVMSG $out_chan :$data"
}
}
In this case, you've got the foreach-loop outside the next_proc proc, I suppose that's not what you intended. Also, there's one stray } after the back_proc proc.
NML_375
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

Removed the extra brace now get this error

Code: Select all

[17:34] can't read "take_all": no such variable
    while executing
"foreach txt_line $take_all {
  if {$txt_line != ""} {
    putquick "PRIVMSG $out_chan :$txt_line"
  }
}"
[/code]
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

blake wrote:Removed the extra brace now get this error

Code: Select all

[17:34] can't read "take_all": no such variable
    while executing
"foreach txt_line $take_all {
  if {$txt_line != ""} {
    putquick "PRIVMSG $out_chan :$txt_line"
  }
}"
[/code]
removed the brace before foreach this is how its looking getting no errors

Code: Select all

set out_chan "#Trainingroom"
set txt_file "Training.txt"
bind pub SA|SA !next next_proc
bind pub SA|SA !back back_proc

proc next_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !next <linenumber>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  foreach txt_line $take_all {
  if {$txt_line != ""} {
    putquick "PRIVMSG $out_chan :$txt_line"
  }
}

proc back_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !back <line number>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  set data [lindex $take_all [expr $line - 1]]
  putquick "PRIVMSG $out_chan :$data"
}
}
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

Have sorted it so its outputting the text of the file any help with line numbers i want to be able to just type !next and it display the next line without having to do !next linenumber
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Code still looks broken, and your braces {} are still out of order..
You currently get away with it if you execute !next atleast once before executing !back, since you actually managed to nest back_proc inside next_proc.

This is how it should look, and the point of indenting is to keep track of how many "nested" braces you've got.. add one {, indent one step more.. add one }, indent one step less...

Code: Select all

set out_chan "#Trainingroom"
set txt_file "Training.txt"
bind pub SA|SA !next next_proc
bind pub SA|SA !back back_proc

proc next_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !next <linenumber>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  foreach txt_line $take_all {
    if {$txt_line != ""} {
      putquick "PRIVMSG $out_chan :$txt_line"
    }
  }
}

proc back_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !back <line number>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  set data [lindex $take_all [expr $line - 1]]
  putquick "PRIVMSG $out_chan :$data"
}
For your !next without linenumbers, you'd have to keep a counter for the displayed line. Should this be user-specific, channel-specific, global, or something else?
NML_375
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

it would channel specific its only used in one room which is #trainingroom and only has one person at anyone time using it
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

slitely changed this script again as it was sending the hole file to channel

id like to be able to change it so the command !tr without linenumber can be typed in the bots pm will still need to read one line at a time fron text file currently we have to type !tr line number in the channel the bot is in the back proc is ok but if that could be set so we can type that in pm also would be great line nimber needs to remain for back proc

Code: Select all

set out_chan "#Trainingroom"
set txt_file "training.txt"
bind pub SA|SA !tr next_proc
bind pub SA|SA !back back_proc

proc tr_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !tr <line number>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  set data [lindex $take_all [expr $line - 1]]
  putquick "PRIVMSG $out_chan :$data"
}

proc back_proc { nick uhost hand chan arg } {
  global out_chan txt_file
  set line [lindex [split $arg] 0]
  if {$line == ""} {
    putserv "PRIVMSG $chan :Usage: !back <line number>"
    return
  }
  set take_me [open $txt_file r]
  set take_all [split [read $take_me] "\n"]
  close $take_me
  set data [lindex $take_all [expr $line - 1]]
  putquick "PRIVMSG $out_chan :$data"
}
Post Reply