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.

[Solved] Need some help again :\

Help for those learning Tcl or writing their own scripts.
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

[Solved] Need some help again :\

Post by Red_Rooste5 »

Well This is my newly updated invite script.

Code: Select all

bind raw - INVITE invites:join

proc invites:join {from key arg} {
  set chan [string range [lindex [split $arg] 1] 1 end]
set chans [llength [split [channels]]]
set nick [lindex [split $from !] 0]
if {$chans == 30} {
putquick "NOTICE $nick :This bot is currently full, searching for other bots."
putquick "PRIVMSG #boombot :join $chan"
utimer 10 [list invites:joinmsg $chan $nick]
return
if {$chans < 30} {
   channel add $chan
return
  }
}

set requirement 5

proc invites:joinmsg {nick uhost hand chan} {
global requirement
set chans [llength [chanlist $chan]]
if {$chans < $requirement} {
putquick "PART $chan :You need atleast 5 users to have this bot in your channel$
channel remove $chan
if {[onchan \[De\]BoomBot $chan]} {
putlog "OMG \[De\]BoomBot is on $chan"
putquick "PART $chan You already have a BoomBot in your chan."
channel remove $chan
}
return
}
if {$chans >= 5} {
if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
return
}
}
}
}
That's on the first bot

Code: Select all

bind pub * join join:de
proc join:de {nick uhost hand chan text} {
if {[string equal -nocase BoomBot $nick]} {
channel add $text
}
}

bind join * {*} joinmsg:de
proc joinmsg:de {nick uhost hand chan} {
if {llength [split [chanlist $chan]]] < 5} { putquick "PART $chan :You need atl$
channel remove $chan
}
}
{
if {[string equal -nocase \[De\]BoomBot $nick]} {
if {[llength [split [chanlist $chan]]] > 5} {
putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
}
}
}
That's on the second one.

Well... The first problem on the first bot is that it won't join...
And the second bot won't even start with that script.

On the first script, it's meant to get the invite, but if the bot is on 30 channels, it'll message #boombot join $chan but if it's not on 30 channels it will join, though if the channel has 5 or less users, it will part. And on the second one, it's meant to look after "join #chan" and join the channel if "BoomBot" is the one saying the command.
Last edited by Red_Rooste5 on Sat Dec 16, 2006 3:41 am, edited 3 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Please indent your code properly.
Doing so would make it obvious you failed to "close" the first conditional body (sending the message 'bout full bot).
Hence, the second if-conditional will only be reached if chans is equal to 30. At the same time, for this second conditional to be true, chans must be less than 30 (which it can't be).

Solution: Indent properly and get your { and } in order

Second script is similar... Properly indented, it would look like this; where the error would be obvious:

Code: Select all

bind pub * join join:de
proc join:de {nick uhost hand chan text} {
 if {[string equal -nocase BoomBot $nick]} {
  channel add $text
 }
}

bind join * {*} joinmsg:de
proc joinmsg:de {nick uhost hand chan} {
 if {llength [split [chanlist $chan]]] < 5} {
  putquick "PART $chan :You need atl$"
  channel remove $chan
 }
}


{
 if {[string equal -nocase \[De\]BoomBot $nick]} {
  if {[llength [split [chanlist $chan]]] > 5} {
   putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
  }
 }
}
Edit: Just to make clear, the above script is not fixed, just had some proper indenting to actually make the error visible. Don't expect it to run.
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Anyways, what do you mean by "It can't be on less then 30 channels"?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Simply, if you actually study your conditionals (if-then-else constructs), you'd see that the only time this is actually executed:

Code: Select all

if {$chans < 30} {...
is when the conditional:

Code: Select all

if {$chans == 30} {...
is fulfilled...

So, whenever this part of the code:

Code: Select all

if {$chans < 30} {...
is executed, chans will be 30 and nothing else.. 30 is not less than 30, hence it will always be false, and your bot will never join the channel...
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Sooo... What I gotta do here is that I need to change the if's to =< ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

NO!
What you need is this:
Solution: Indent properly and get your { and } in order
Changing the comparison operator in the second if-statement wont change the fact that it will only be run when the first if-statement is true (chans == 30).

Edit: Also, since there's a return-command within the first conditional, prior to the second if-statement, the second if-statement won't be evaluated even if chans == 30.
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Erm... I really don't get your point. What should I do with the script itself?
Do I need to remove the return on the first statement or what?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

No, you need to get your braces ({ and }) in order.
If you don't understand this, I suggest you study the tcl manual, especially this part.
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Well.. I got that working now, but it now gives me this:

Code: Select all

[15:35] can't read "chans": no such variable
    while executing
"if {$chans >= 5} {
if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
return
}
}"
    (file "scripts/invite1.tcl" line 36)
    invoked from within
"source scripts/invite1.tcl"
    (file "eggdrop.conf" line 1353)
[15:35] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
Script:

Code: Select all

bind raw - INVITE invites:join

proc invites:join {from key arg} {
  set chan [string range [lindex [split $arg] 1] 1 end]
set chans [llength [split [channels]]]
set nick [lindex [split $from !] 0]
if {$chans == 30} {
putquick "NOTICE $nick :This bot is currently full, searching for other bots."
putquick "PRIVMSG #boombot :join $chan"
utimer 10 [list invites:joinmsg $chan $nick]
return
}
if {$chans < 30} {
   channel add $chan
return
  }
}

set requirement 5

proc invites:joinmsg {nick uhost hand chan} {
global requirement
set chans [llength [chanlist $chan]]
if {$chans < $requirement} {
putquick "PART $chan :You need atleast 5 users to have this bot in your channel$
channel remove $chan
}
elseif {[onchan \[De\]BoomBot $chan]} {
putlog "OMG \[De\]BoomBot is on $chan"
putquick "PART $chan You already have a BoomBot in your chan."
channel remove $chan
}
return
}
global chans
if {$chans >= 5} {
if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
return
}
}
}
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

And once again, if you actually bothered to indent your code, you'd be able to see the problem yourself... Which still is the fact that you've lost track of your braces... Adding to that, you add a "global chans" while already in globalspace, and also do further matchins on variables not defined in globalspace (that is, you've already "ended" the second proc when you reach the point where you write "global chans").

Obviously, this is an error due to the fact that you've lost track on your { }. Properly indenting your code helps you with that. Any further code-parts you post that are not indented, will be ignored on my behalf...
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Code: Select all

bind raw - INVITE invites:join
 proc invites:join {from key arg} {
 set chan [string range [lindex [split $arg] 1] 1 end]
 set chans [llength [split [channels]]]
 set nick [lindex [split $from !] 0]
 if {$chans == 30} {
  putquick "NOTICE $nick :This bot is currently full, searching for other bots."
  putquick "PRIVMSG #boombot :join $chan"
  utimer 10 [list invites:joinmsg $chan $nick]
  return
 }
 if {$chans < 30} {
  channel add $chan
  putquick "PRIVMSG $chan :\00302BoomBot version 1.9 by \00307Red_Rooste5"
  return
  }
}

set requirement 5

proc invites:joinmsg {nick uhost hand chan} {
 global requirement
 set chans [llength [chanlist $chan]]
  if {$chans < $requirement} {
   putquick "PART $chan :You need atleast 5 users to have this bot in your chan$
   channel remove $chan
  }
 elseif {[onchan \[De\]BoomBot $chan]} {
  putlog "OMG \[De\]BoomBot is on $chan"
  putquick "PART $chan You already have a BoomBot in your chan."
  channel remove $chan
  return
 }
}
if {$chans >= 5} {
 if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
  return
 }
}
There. I atleast tried to indent dunno if I made it right or not :\
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Indention is roughly correct (or correct enough).
Should be quite obvious now that

Code: Select all

if {$chans >= 5} {
 if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
  return
 }
}
is not part of the body of invites:joinmsg, but instead is executed in globalspace when your script is loaded (and at that point, there's no chans-variable defined, and both nick and botnick have special meaning here. Also, using return in globalspace might not be such a good idea. I'm guessing that code-snipped rather should be part of invites:joinmsg, and hence the solution is trivial.
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

Well, I did update the script after intending it.

Code: Select all

bind raw - INVITE invites:join
 proc invites:join {from key arg} {
 set chan [string range [lindex [split $arg] 1] 1 end]
 set chans [llength [split [channels]]]
 set nick [lindex [split $from !] 0]
 if {$chans == 30} {
  putquick "NOTICE $nick :This bot is currently full, searching for other bots."
  putquick "PRIVMSG #boombot :join $chan"
  utimer 10 [list invites:joinmsg $chan $nick]
  return
 }
 if {$chans < 30} {
  channel add $chan
  putquick "PRIVMSG $chan :\00302BoomBot version 1.9 by \00307Red_Rooste5"
  return
  }
}

set requirement 5

proc invites:joinmsg {nick uhost hand chan} {
 global requirement
 set nickonchan [llength [chanlist $chan]]
  if {$nickonchan > $requirement} {
   putquick "PART $chan :You need atleast 5 users to have this bot in your chan$
   channel remove $chan
  }
 elseif {[onchan \[De\]BoomBot $chan]} {
  putlog "OMG \[De\]BoomBot is on $chan"
  putquick "PART $chan You already have a BoomBot in your chan."
  channel remove $chan
  return
 }
elseif {$nickonchan =< $requirement} {
 if {[string equal -nocase $::botnick $nick]} {
  putquick "PRIVMSG $chan :\00302BoomBot v1.9 by \00307Red_Rooste5"
  return
 }
}
}
So it starts now, but doesnt part or anything. And nothing is on the pl either.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You should not have any newline in front of else or elseif
Incorrect:

Code: Select all

}
elseif {....} {
Correct:

Code: Select all

} elseif {.....} {
Also, I see a logical error:

Code: Select all

if {$nickonchan > $requirement} {
This would be true if there are more than 5 members in the channel, not less
NML_375
R
Red_Rooste5
Voice
Posts: 37
Joined: Sat Oct 21, 2006 7:43 am

Post by Red_Rooste5 »

EDIT: Nvm :P
Post Reply