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.

$var

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dutch1918
Voice
Posts: 14
Joined: Wed Jul 30, 2014 10:30 am

$var

Post by dutch1918 »

I have a $var that has data +###.## or -###.##. What I want to do is "if the $var has +###.## then do something. This is what I have thus far but it doesn't work...

Code: Select all

if {[$change]!="+"} {
        putserv "PRIVMSG $channel :\[\00304DJIA\017]\00303 --> $last $change\017 | $timestamp"
        } else {
		putserv "PRIVMSG $channel :\[\00304DJIA\017]\00304 --> $last $change\017 | $timestamp"
        }	
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Hi,

you should use string first to get what you want:

Code: Select all

if {[string first "+" $var] == 0]} {
	putserv "PRIVMSG $channel :\[\00304DJIA\017]\00303 --> $last $change\017 | $timestamp"
} elseif {[string first "-" $var] == 0]} {
	putserv "PRIVMSG $channel :\[\00304DJIA\017]\00304 --> $last $change\017 | $timestamp" 
}
Once the game is over, the king and the pawn go back in the same box.
d
dutch1918
Voice
Posts: 14
Joined: Wed Jul 30, 2014 10:30 am

Post by dutch1918 »

I get the following error back:

Tcl error [pub:test]: invalid character "]" in expression "...irst "+" $change] == 0]"

After further research I resolved it. Here is the correct syntex:

Code: Select all

set plus [string first "+" $change]
set minus [string first "-" $change]
	if {$plus == !1} { 
        putserv "PRIVMSG $channel :\[\00312DJIA\017]\002 -->\017 \00303$last $change\017 | $timestamp"
        } elseif {$minus == !1} {
		putserv "PRIVMSG $channel :\[\00312DJIA\017]\002 --> \017\00304$last $change\017 | $timestamp"
        } else {
		putserv "PRIVMSG $channel :\[\00312DJIA\017]\002 --> $last \017 | $timestamp"
	}
}
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Code: Select all

{$minus == !1}
is wrong the !

it should with == as in != ex
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Post Reply