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 join/part script

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Repdientu
Voice
Posts: 37
Joined: Thu Apr 30, 2009 3:45 am
Location: Viet Nam
Contact:

help join/part script

Post by Repdientu »

Hello
i write script to join(part) script but it not work (bot part but not join #)

here is my script

Code: Select all

set p_chan "#Lobby"


set p_time 5


proc joinpart_start {} {
  global p_time
  if {[string match *p_joinpart* [timers]]} {return 0}
  timer [expr [rand $p_time] + 1] p_joinpart
}

proc p_joinpart {} {
  global botnick p_chan p_time
  if {[onchan $botnick $p_chan]} {
    channel remove $p_chan
  }
  if {![onchan $botnick $p_chan]} {
    channel add $p_chan
  }
  timer [expr [rand $p_time] + 1] p_joinpart
}

set p_chan [string tolower $p_chan]

joinpart_start
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hello,
The first thing that comes to mind, is that "onchan" only works for channels added to your eggdrop's channel-list. As such, your script would then crash once your eggdrop has left the channel.

The options I see, is either to use the "inactive" channel modifier to temporarily disable the channel (rather than delete it); or if you still prefer to delete it, you'd have to use "validchan" to check whether the channel is valid, rather than using "onchan" (or "botonchan" for that matter).
NML_375
R
Repdientu
Voice
Posts: 37
Joined: Thu Apr 30, 2009 3:45 am
Location: Viet Nam
Contact:

Post by Repdientu »

i change script to:

Code: Select all

set p_chan "#Lobby"


set p_time 5


proc joinpart_start {} {
  global p_time
  if {[string match *p_joinpart* [timers]]} {return 0}
  timer [expr [rand $p_time] + 1] p_joinpart
}

proc p_joinpart {} {
  global botnick p_chan p_time
  if {![validchan $p_chan]} {
    channel add $p_chan
  }
  else  {
    channel remove $p_chan
  }
  timer [expr [rand $p_time] + 1] p_joinpart
}

set p_chan [string tolower $p_chan]

joinpart_start
but it not work. can you help me ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The only obvious error I can see in this code, is that you've placed "else {" on a separate line.
Unlike languages like C, Java, etc; tcl is strictly newline-terminated outside blocks. As your code stands now, tcl tries to interpret "else" as a new command, as opposed to an argument to "if":

Code: Select all

// this is ok
if {some expression} then {
  code here
} else {
  other code here
}

//or simplified
if {some expression} {
  code here
} {
  other code here
}

//or condensed
if {some expression} {code here} {other code here}


// these however will not work
if {some expression}
{
  code here
}
...
// then-body is not part of the if-command due to the newline _before_ {

if {some expression} {
  code here
} else
{
  code here
}
// else-body is not part of the if-command due to the newline _before_ {

if {some expression} {
  code here
}
else {
  code here
}
// else-keyword and -body is not part of the if-command due to the newline _before_ else
Hope these examples illustrate the issue
NML_375
Post Reply