| View previous topic :: View next topic |
| Author |
Message |
dutch1918 Voice
Joined: 30 Jul 2014 Posts: 14
|
Posted: Fri Oct 03, 2014 7:17 pm Post subject: $var |
|
|
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: |
if {[$change]!="+"} {
putserv "PRIVMSG $channel :\[\00304DJIA\017]\00303 --> $last $change\017 | $timestamp"
} else {
putserv "PRIVMSG $channel :\[\00304DJIA\017]\00304 --> $last $change\017 | $timestamp"
}
|
|
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Oct 04, 2014 3:16 am Post subject: |
|
|
Hi,
you should use string first to get what you want:
| Code: |
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. |
|
| Back to top |
|
 |
dutch1918 Voice
Joined: 30 Jul 2014 Posts: 14
|
Posted: Sat Oct 04, 2014 8:33 am Post subject: |
|
|
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: |
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"
}
}
|
|
|
| Back to top |
|
 |
Fire-Fox Master

Joined: 23 Sep 2006 Posts: 270 Location: /dev/null
|
Posted: Sat Oct 04, 2014 3:41 pm Post subject: |
|
|
is wrong the !
it should with == as in != ex _________________ GreatZ
Fire-Fox | Denmark
Scripts: Relay | Store Text | TvMaze |
|
| Back to top |
|
 |
|