egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help join/part script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Repdientu
Voice


Joined: 30 Apr 2009
Posts: 33
Location: Viet Nam

PostPosted: Sat Oct 05, 2019 2:11 am    Post subject: help join/part script Reply with quote

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

here is my script
Code:

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
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Oct 05, 2019 12:57 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Repdientu
Voice


Joined: 30 Apr 2009
Posts: 33
Location: Viet Nam

PostPosted: Sat Oct 05, 2019 11:56 pm    Post subject: Reply with quote

i change script to:
Code:

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 ?
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Oct 06, 2019 5:37 am    Post subject: Reply with quote

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:
// 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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber