| View previous topic :: View next topic |
| Author |
Message |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Thu Feb 17, 2011 5:50 pm Post subject: varibles help |
|
|
Hi, im very new to tcl scripting .
Anyways i have made a little test to see how varibles would work but i keep running into ptoblems and have searched all sorts of docs and tryed always to make this happen but always fail.
| Code: | bind pub - ".ctest" ctest
proc ctest {nick host hand channel text} {
if {$text == on} {
set temptest "on"
putmsg ###1 "ctest is now $temptest"
}
if {$text == off} {
set temptest "off"
putmsg ###1 "ctest is now $temptest"
}
if {$text == check} {
putmsg ###1 "ctest is currently $temptest"
}
} |
The first 2 work fine but the "check" does not :/
Thanks
Gemster |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Feb 17, 2011 8:52 pm Post subject: Re: varibles help |
|
|
There is nothing to set temptest after the if command that looks for check.
Next, try enclosing in double quotes.
Example:
if {$text == "check"}
In another thread of yours, ( http://forum.egghelp.org/viewtopic.php?p=96036&highlight=suninet#96036 )
I mentioned this site:http://suninet.the-demon.de/
I suspect that you haven't been through that whole thing yet.
Here:
http://suninet.the-demon.de/071.htm
it specifically says to enclose in double quotes.
There are times that you don't need to do so. I'm not the one to explain that. Nor have I spent time researching it.
And I can't tell you why it seems to work ok in the first two if statements, with
on
and
off.
Maybe a guru can jump in here and explain that.
I did experiment with your little script, both with and without double quotes around the word "check".
Try it for yourself. Both ways. Be logged in to the partyline of your bot when you do, and watch for error messages. You'll see.
By the way, I think that experimenting like you are doing is great!
Keep it up. |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Fri Feb 18, 2011 3:21 am Post subject: |
|
|
Hi willyw
| Quote: | | There is nothing to set temptest after the if command that looks for check. |
The first 2 sets the varible and the check just displays it in the chan, no need. For example it displays if something is on/off.
I have read that site and useing it for reference. it states that its | Code: | | set varname "something here" | in quotes like i have.
For if statements it says that anything inside of quotes is counted as plain text. Also i took the if statement examples from there too.
Anyways i tryed what you posted and yet the first 2 works but when it comes to the "check" it throws something like "no such varible "temptest".
Thanks
Gemster |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Fri Feb 18, 2011 3:35 am Post subject: |
|
|
ok tryed this
| Code: | bind pub - ".ctest" ctest
proc ctest {nick host hand channel text} {
if {$text == "on"} {
set temptest "on"
putmsg ###1 "ctest is now $temptest"
}
if {$text == "off"} {
set temptest "off"
putmsg ###1 "ctest is now $temptest"
}
if {$text == "check"} {
putmsg ###1 "ctest is currently $temptest"
}
} |
Then in the channel:
[07:31] <Gemster> .ctest on
[07:31] <Stoner> ctest is now on
[07:31] <Gemster> .ctest off
[07:31] <Stoner> ctest is now off
[07:32] <Gemster> .ctest check
then in the eggdrops partyline:
Tcl error [ctest]: can't read "temptest": no such variable
:/ still dont work.
Thanks
Gemster |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Fri Feb 18, 2011 9:28 am Post subject: |
|
|
global | Code: | proc ctest {nick host hand channel text} {
global temptest |
_________________ TCL the misunderstood |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri Feb 18, 2011 10:21 am Post subject: |
|
|
| Gemster wrote: |
| Quote: | | There is nothing to set temptest after the if command that looks for check. |
The first 2 sets the varible and the check just displays it in the chan, no need. For example it displays if something is on/off.
|
Ah. Ok.
I didn't understand what your intention was.
| Quote: |
I have read that site and useing it for reference.
|
I hope you found it a good place to start.
| Quote: |
it states that its | Code: | | set varname "something here" | in quotes like i have.
For if statements it says that anything inside of quotes is counted as plain text. Also i took the if statement examples from there too.
|
Well... it has been quite a while since I myself went through that site, top to bottom.
Perhaps I was skimming too quickly... but on this page, http://suninet.the-demon.de/071.htm
I see:
"This can be two strings, .... or some text (enclosed in quotes like also told in Chapter 3.3) "
| Quote: |
Anyways i tryed what you posted and yet the first 2 works but when it comes to the "check" it throws something like "no such varible "temptest".
|
And TCL_no_TK has illustrated the solution.
The explantion is here: http://suninet.the-demon.de/055.htm
I hope this helps.
Hang in there... keep experimenting.  |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Fri Feb 18, 2011 6:07 pm Post subject: |
|
|
| TCL_no_TK wrote: | global | Code: | proc ctest {nick host hand channel text} {
global temptest |
|
Thanks TCL_no_TK, that done the trick.
Yes willyw, http://suninet.the-demon.de/ is a great site, i love it .
Im working my way down it and if i see something that i like i try to code with it.
So far ive made quite a good script with commands that i have found and got working
Heres an example to show how much ive learned so far for if statments and global/local vars:
| Code: | #Tssync
bind pub - ".tssync" tssync
proc tssync {nick host hand channel text} {
global tss
if {[onchan $nick #opers] == 1 && [isop $nick #opers] == 1} {
if {$text == "on"} {
set tss "on"
putserv "PRIVMSG #opers :TSSync turned \0034\002ON\002\003 by \00310$nick\003."
bind cron - "0 * * * *" tssync_doit
}
if {$text == "off"} {
set tss "off"
putserv "PRIVMSG #opers :TSSync turned \0034\002OFF\002\003 by \00310$nick\003."
unbind cron - "0 * * * *" tssync_doit
}
if {$text == "check"} {
putmsg #opers "Tssync is currently $tss"
}
if {$text != "on" && $text != "off" && $text != "check"} {
putquick "NOTICE $nick : syntax is .tssync on/off/check"
}
} else {
putmsg #opers "Sorry \00310$nick\003, you dont have access to use that command"
}
}
proc tssync_doit {min hour day month weekday} {
putserv "PRIVMSG OperServ :tssync"
} |
Its not that good i know and there will be plenty of room in that little code for improvements but as im just starting to get the hang of it im quite proud of that little code
Thanks
Gemster |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Feb 19, 2011 4:53 am Post subject: |
|
|
You should 'split' the $text and take what you need from it with 'lindex'
| Code: |
set text [lindex [split $text] 0]
|
| Quote: |
if {[onchan $nick #opers] == 1 && [isop $nick #opers] == 1} {
|
there's no need to check bouth, stick with just the isop as it wil return 1 if that user is on the channel and has op, else will return 0.
Also, here's another tip:
| Code: |
if {$something} {
will do this part if $something is equal with 1
}
if {!$something} {
will do this part if $something is equal with 0
}
|
| Quote: |
if {$text == "on"} {
|
You should start using either [string tolower $text] or [string match -nocase $text "on"] (same thing for "off" and "check") as "ON" isn't the same thing as 'on' and the script won't work
I would replace:
| Code: |
if {$text != "on" && $text != "off" && $text != "check"} {
putquick "NOTICE $nick : syntax is .tssync on/off/check"
}
|
with something easier to change:
| Code: |
set commands [list "on" "off" "check"]
if {![lsearch -exact $commands $text]} {
putquick "NOTICE $nick : syntax is .tssync on/off/check"
}
|
OR use 'switch -nocase -- $text' like i did on the other topic that would take care of other inputs for you.
| Code: |
switch -nocase -- [lindex [split $text] 0] {
"on" {
# on stuff here
}
"off" {
# off stuff here
}
"check" {
# check stuff here
}
default {
# any other command goes here
}
}
|
Move the 'if' check that sends this message:
| Code: |
putmsg #opers "Sorry \00310$nick\003, you dont have access to use that command"
|
at top and return after like this:
| Code: |
if {![isop $nick "#opers"]} {
putserv "PRIVMSG #opers :Sorry \00310$nick\003, you dont have access to use that command"
return
}
|
Here's my version of your code with 'switch':
| Code: |
bind pub - ".tssync" pub:tssync
proc pub:tssync {nick uhost hand chan text} {
global tss
if {![isop $nick "#opers"]} {
putserv "PRIVMSG $chan :Sorry \00310$nick\003, you dont have access to use that command"
return
}
switch -nocase -- [lindex [split $text] 0] {
"on" {
set tss "on"
putserv "PRIVMSG $chan :TSSync turned \0034\002ON\002\003 by \00310$nick\003."
bind cron - "* */1 * * *" cron:tssync
}
"off" {
set tss "off"
putserv "PRIVMSG $chan :TSSync turned \0034\002OFF\002\003 by \00310$nick\003."
unbind cron - "* */1 * * *" cron:tssync
}
"check" {
putserv "PRIVMSG $chan :TSSync is currently $tss"
}
default {
putserv "NOTICE $nick : syntax is .tssync on/off/check"
}
}
}
proc cron:tssync {min hour day month weekday} {
putserv "PRIVMSG OperServ :tssync"
}
|
Edit: Fixed minor typos and added the missing bind.  _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Thu Feb 24, 2011 3:08 pm; edited 5 times in total |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat Feb 19, 2011 10:32 am Post subject: |
|
|
Take time to read this and bookmark it :
http://www.peterre.info/characters.html
Bookmark it, because you'll want to return to it, and re-read it too.
| Quote: |
How to write eggdrop scripts that won't choke on special characters
by "Peterre"
|
|
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Thu Feb 24, 2011 9:59 am Post subject: |
|
|
caesar, your code does not work :/
When i do ".tssync on" i get this error:
| Quote: |
Tcl error [tssync]: invalid command name "tssync"
|
Thanks
Gemster |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Feb 24, 2011 2:42 pm Post subject: |
|
|
Oh snap. </facepalm>
You get that error because you are using your old bind instead of the one I should have included in my previous post.
Before the:
| Code: |
proc pub:tssync {nick uhost hand chan text} {
|
add:
| Code: |
bind pub * .tssync pub:tssync
|
and remove other code. I've made this change in my previous post too.
Edit: Here's a enhanced version, one that is bug free (do a .tssync on or off twice and see what happens)
| Code: |
bind pub - ".tssync" pub:tssync
proc pub:tssync {nick host hand chan text} {
if {![string match -nocase $chan "#opers"]} return
if {![isop $nick #opers]} {
putserv "PRIVMSG $chan :Sorry \00310$nick\003, you dont have access to use that command"
return
}
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {![bind:check "cron:tssync"]} {
bind cron - "* */1 * * *" cron:tssync
putserv "PRIVMSG $chan :TSSync turned \0039\002ON\002\003 by \00310$nick\003."
} else {
putserv "PRIVMSG $chan :TSSync is already \0039\002OFF\002\003."
}
}
"off" {
if {[bind:check "cron:tssync"]} {
unbind cron - "* */1 * * *" cron:tssync
putserv "PRIVMSG $chan :TSSync turned \0034\002OFF\002\003 by \00310$nick\003."
} else {
putserv "PRIVMSG $chan :TSSync is already \0034\002OFF\002\003."
}
}
"check" {
if {[bind:check "cron:tssync"]} {
set status "\0039\002ON\002\003"
} else {
set status "\0034\002OFF\002\003"
}
putserv "PRIVMSG $chan :TSSync is currently $status"
}
default {
putserv "NOTICE $nick :Correct syntax is: \002.tssync on/off/check\002"
}
}
}
proc bind:check {name} {
set status 0
foreach {type flags command hits bind} [join [binds]] {
if {[string equal -nocase $bind $name]} {
set status 1
break
}
}
return $status
}
proc cron:tssync {min hour day month weekday} {
putserv "PRIVMSG OperServ :tssync"
}
|
I took the liberty to make it work only in #opers channel. You should remove the 'if {![string match -nocase $chan "#opers"]} return' line if don't want this behavior. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Thu Feb 24, 2011 8:52 pm Post subject: |
|
|
Wow caesar lol,
Slow down
Im still learning rember. Anyways let me get the first code posted working then ill move onto your last version, By looking at the code i see it checks the var when u do on/off.
Anyways befor i test that code and learn that id like to learn the first 1 and get that sorted befor i move on
well, the first version i done what u sed but i still get errors:
Tcl error [pub:tssync]: bad option "-nocase": must be -exact, -glob, -regexp, or --
Thanks
Gemster |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Feb 25, 2011 2:31 am Post subject: |
|
|
I think you have an older version of TCL, cos in version 8.5.8 that I have the 'nocase' option exist. Anyway, replace the:
| Code: |
switch -nocase -- [lindex [split $text] 0] {
|
with:
| Code: |
switch -- [string tolower [lindex [split $text] 0]] {
|
and should work just fine.
In the second code with the 'bind:check' proc I do a check if the bind exists or not, cos if it exists and you want to create it again, or delete something that doesn't exist will give you an error. I just covered all the possible errors.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Fri Feb 25, 2011 7:11 am Post subject: |
|
|
Thanks caesar,
It now works but i found another problem :/
"* */1 * * *" makes it do it every 1 min not once an hour.
Thanks
Gemster |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
|
| Back to top |
|
 |
|