egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with decreasing a variable

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sat Jun 24, 2006 5:45 pm    Post subject: Problem with decreasing a variable Reply with quote

Hello!
In one of my scripts there is this line:
Code:
incr i [lindex $line 0]

But now I don't want to increase it but I want to decrease it. So I changed it to this:
Code:
incr i [lindex $line 0] -1

It does not work. The error is: Tcl error [flag]: wrong # args: should be "incr varName ?increment?"
What's wrong?
Back to top
View user's profile Send private message
Garp
Voice


Joined: 15 Sep 2003
Posts: 29

PostPosted: Sat Jun 24, 2006 9:17 pm    Post subject: Re: Problem with decreasing a variable Reply with quote

darton wrote:
Code:
incr i [lindex $line 0] -1


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:
set i [expr [incr i [lindex $line 0]] -1]
Back to top
View user's profile Send private message
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Sat Jun 24, 2006 11:15 pm    Post subject: Reply with quote

simply:
Code:
incr i -1


in the script you have '[lindex $line 0]' is used to obtain the increment value
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun Jun 25, 2006 6:15 am    Post subject: Reply with quote

With the '[lindex $line 0]' it is defined what should be increased. So none of your scripts work.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Jun 25, 2006 7:40 am    Post subject: Reply with quote

Code:
incr i -[lindex $line 0]

this will decrement i by '[lindex $line 0]' instead of increment.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun Jun 25, 2006 9:09 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Sun Jun 25, 2006 9:43 am    Post subject: Reply with quote

if
Code:
[lindex $line 0]
is "2"
Code:
incr i -[lindex $line 0]

means that it is increased by -2, which means it is decreased by 2
obviously you didn't bother to try it[/code]
Back to top
View user's profile Send private message
phab
Voice


Joined: 22 Aug 2005
Posts: 12

PostPosted: Mon Jun 26, 2006 5:59 pm    Post subject: Reply with quote

Doenst
Code:
set i [expr {$i - [lindex $line 0]}]
work?
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue Jun 27, 2006 3:35 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber