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.

timer and timer id

Old posts that have not been replied to for several years.
Locked
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

timer and timer id

Post by SaPrOuZy »

Code: Select all

utimer $X {
    statement1
    statement2
    statement3
    ...
}
how can i get the utimer id when?
i know it's usually set timerID [utimer x bla]
but when i have the timer the way i put it, (with a {} chunk) is
using the following correct?

Code: Select all

set timerID [utimer $X {
    statement1
    statement2
    statement3
    ...
}]
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

try it

beware however that your statements body will be evaluated outside the context of [utimer]
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

i wish i could try it now, am writing the script at work hehe

i didn't get what is exactly meant by "your statements body will be evaluated outside the context of [utimer]"
they wont execute after X seconds? or what?
how about if i made them

Code: Select all

set timerID [utimer $X {statement1;statement2;statement3;}]
does it make any difference?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

no it doesn't

suppose you have:

Code: Select all

proc foo {nick uhost hand chan args} {
   set tid [utimer 10 {putchan $chan "$nick, you are lame"}]
}
this will raise an error when the timer expires:

Code: Select all

Tcl error: can't read "chan": no such variable
because when your [utimer] script is evaluated, current execution point is no longer inside proc [foo], and $chan is variable local to that proc; furthermore, the braces you use prevent variable substitution when the interpreter is still executing your [utimer] statement inside [foo]

you should use
  • instead, to force variable substitution:

    Code: Select all

    proc foo {nick uhost hand chan args} {
       set tid [utimer 10 [list putchan $chan "$nick, you are lame"]]
    }
    
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

yea i noticed, i was working at it at night. i solved it by making the timer call a procedure instead of shuving everything in the {}
i still have a question to ask , but am late i'll get back to it in about an hour when am at work and am free.

thanks alot for your help
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if you want multiline without {} you can always escape (blackslash) the newline character like

Code: Select all

set timerID [utimer $X \
    statement1;\
    statement2;\
    statement3;\
    ... \
]
this will ensure evalation of vars ands commands inside and still keep the visual advantage of multiline ^^
alternately you should be able to do:

Code: Select all

eval {set timerID [utimer $X 
    statement1;
    statement2;
    statement3;
    ...
]}
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...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

De Kus wrote:if you want multiline without {} you can always escape (blackslash) the newline character like

Code: Select all

set timerID [utimer $X \
    statement1;\
    statement2;\
    statement3;\
    ... \
]
this is incorrect

backslash is needed only if you want to break a statement; in your code you are breaking [utimer] invocation, but whitespaces will still cause an error, since [utimer] expects fixed number of arguments, it's not like [concat] or [eval]
this will ensure evalation of vars ands commands inside and still keep the visual advantage of multiline ^^
wrong, backslash has nothing to do with evaluation whatsoever
alternately you should be able to do:

Code: Select all

eval {set timerID [utimer $X 
    statement1;
    statement2;
    statement3;
    ...
]}
you should try it yourself before recommending it; that won't work at all
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

sorry sorry sorry for forgetting the "" quotes, but with these it works... this time tested :P.
[21:33:07] #De_Kus# set X 1
Ok, set.
.loadtcl test
[21:33:15] #De_Kus# loadtcl test
hi2
im2
cool2
hi
im
cool
content of test.tcl:

Code: Select all

set timerID1 [utimer $X "\
    putdcc 11 hi;\
    putdcc 11 im;\
    putdcc 11 cool;\
"]

eval {set timerID2 [utimer $X "
    putdcc 11 hi2;
    putdcc 11 im2;
    putdcc 11 cool2;
"]}
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...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

yeah it works that way, and you are crying to be hacked or at least exploited :P

see Script Security topic in FAQ forum
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Locked