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.

syntax error in expression

Help for those learning Tcl or writing their own scripts.
Post Reply
K
Keen
Voice
Posts: 10
Joined: Wed Jan 28, 2009 7:47 pm

syntax error in expression

Post by Keen »

hello i try to if then else syntax aber i see this error on ctcp chat windows with my bot.

Tcl error [opekle]: syntax error in expression "$ahmet!=Jesus": variable references require preceding $


tcl codes are:


set wnick "Jesus"

bind pub - !opekle opekle
proc opekle {nick host hand chan text} {
global ahmet
set wnick [lindex $text 0]
if {$wnick!=Jesus} {
putserv "privmsg $chan :You are not Jesus."
}
else {
putserv "privmsg $chan :You are Jesus."
}
}


what is the problem? what is wrong please help me thanx
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: syntax error in expression

Post by speechles »

Code: Select all

if {$wnick!="Jesus"} {
Try using quotes around a literal expression perhaps? Your next error will be invalid command name: else because for some reason you close the if clause and put the else on the next line... Don't complain it's case-sensitive either, you wrote it :P
Last edited by speechles on Wed Jan 28, 2009 8:20 pm, edited 2 times in total.
K
Keen
Voice
Posts: 10
Joined: Wed Jan 28, 2009 7:47 pm

Post by Keen »

thanx a lots it is working


[01:51] <@Jesus> !opekle
[02:01] <@Jesus> !opekle
[02:01] <opLa> You are not Jesus.

[02:03] <@jesus> !opekle
[02:03] <opLa> You are not Jesus.

İt is not case sensitive. and there is no any problem after i use quotes arround literal?

is it okey ?
:)

im very new with tcl. jut for to days ( and im not english so sometimes i cant understand.)

Thanx
K
Keen
Voice
Posts: 10
Joined: Wed Jan 28, 2009 7:47 pm

Post by Keen »

Sorry you are rigt. the second error ist

02:01] <opLa> [18:01] Tcl error [opekle]: invalid command name "else"
[02:03] <opLa> [18:03] Tcl error [opekle]: invalid command name "else"
:)

can you correct the code for me so i can understand what i is wrong?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind pub - !opekle opekle

proc opekle {nick host hand chan text} {
   if {[string equal -nocase $nick "jesus"]} {
      putserv "privmsg $chan :You are Jesus."
   } else {
     putserv "privmsg $chan :You are not Jesus."
   }
}
Last edited by speechles on Wed Jan 28, 2009 8:21 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The problem at hand are these lines:

Code: Select all

}
else {
In tcl, there is no command named "else". Instead, it's a parameter for if. What you need to keep in mind here, is that tcl is newline-terminated, with the exception of newlines within a string (enclosed with either "" or {}).

Simply put, the above should be something like this:

Code: Select all

} else {
NML_375
K
Keen
Voice
Posts: 10
Joined: Wed Jan 28, 2009 7:47 pm

Post by Keen »

İ think i understand. an command and its component must be in the same line ?

not
}
else {

Code: Select all

if ..... {

} else { 

}

is there an Editor for progrraming tcl/eggdtop script? that automatically do this for me ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Keen wrote:İ think i understand. an command and its component must be in the same line ?

not
}
else {

Code: Select all

if ..... {

} else { 

}
Correct.
Keen wrote:is there an Editor for progrraming tcl/eggdtop script? that automatically do this for me ?
I can't think of any specific IDE that keeps track of newlines like that. There are, however, numerous editors/IDE's out there that do support highlighting of tcl-code, one of my favourites being emacs.
NML_375
K
Keen
Voice
Posts: 10
Joined: Wed Jan 28, 2009 7:47 pm

Post by Keen »

Thanx nml375 ii will try to use it. have i nice day
Post Reply