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.
Help for those learning Tcl or writing their own scripts.
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Sat Jun 24, 2006 5:45 pm
Hello!
In one of my scripts there is this line:
But now I don't want to increase it but I want to decrease it. So I changed it to this:
It does not work. The error is: Tcl error [flag]: wrong # args: should be "incr varName ?increment?"
What's wrong?
Garp
Voice
Posts: 29 Joined: Mon Sep 15, 2003 7:58 pm
Post
by Garp » Sat Jun 24, 2006 9:17 pm
you do something like "1 +1 -1" but incr allows only one operation like "1+1" or "1-1"
(($i + $y) - $z) it would be something like
Code: Select all
set i [expr [incr i [lindex $line 0]] -1]
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Sat Jun 24, 2006 11:15 pm
simply:
in the script you have '[lindex $line 0]' is used to obtain the increment value
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Sun Jun 25, 2006 6:15 am
With the '[lindex $line 0]' it is defined what should be increased. So none of your scripts work.
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Jun 25, 2006 7:40 am
this will decrement
i by '[lindex $line 0]' instead of increment.
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Sun Jun 25, 2006 9:09 am
Yes, it works Sir_Fz. But if i is 3 and it should be decreased the result is 2. With your script it is not 2, but -2. With "trimleft" I can make the variable i positive again, but maybe this is too circumstantial and there is an easier way.
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Sun Jun 25, 2006 9:43 am
if
is "2"
means that it is increased by -2, which means it is decreased by 2
obviously you didn't bother to try it[/code]
phab
Voice
Posts: 12 Joined: Mon Aug 22, 2005 6:34 am
Post
by phab » Mon Jun 26, 2006 5:59 pm
Doenst
Code: Select all
set i [expr {$i - [lindex $line 0]}]
work?
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Tue Jun 27, 2006 3:35 am
its equivalent with 'incr i -[lindex $line 0]', however only the expr one will work on negative values.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under
The MIT License
Love hurts, love strengthens...