| View previous topic :: View next topic |
| Author |
Message |
SaPrOuZy Halfop

Joined: 24 Mar 2004 Posts: 75 Location: Lebanon
|
Posted: Tue Sep 20, 2005 3:59 am Post subject: timer and timer id |
|
|
| Code: |
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: |
set timerID [utimer $X {
statement1
statement2
statement3
...
}]
|
|
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Sep 20, 2005 4:30 am Post subject: |
|
|
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] tag when posting logs, code |
|
| Back to top |
|
 |
SaPrOuZy Halfop

Joined: 24 Mar 2004 Posts: 75 Location: Lebanon
|
Posted: Tue Sep 20, 2005 4:34 am Post subject: |
|
|
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: | | set timerID [utimer $X {statement1;statement2;statement3;}] |
does it make any difference? |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Sep 21, 2005 12:41 am Post subject: |
|
|
no it doesn't
suppose you have:
| Code: |
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: |
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 [list] instead, to force variable substitution:
| Code: |
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] tag when posting logs, code |
|
| Back to top |
|
 |
SaPrOuZy Halfop

Joined: 24 Mar 2004 Posts: 75 Location: Lebanon
|
Posted: Wed Sep 21, 2005 12:51 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Wed Sep 21, 2005 1:09 pm Post subject: |
|
|
if you want multiline without {} you can always escape (blackslash) the newline character like
| Code: | 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: | 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... |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Sep 21, 2005 3:07 pm Post subject: |
|
|
| De Kus wrote: | if you want multiline without {} you can always escape (blackslash) the newline character like
| Code: | 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]
| Quote: | | 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
| Quote: | alternately you should be able to do:
| Code: | 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] tag when posting logs, code |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Wed Sep 21, 2005 4:38 pm Post subject: |
|
|
sorry sorry sorry for forgetting the "" quotes, but with these it works... this time tested .
| Quote: | [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: | 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... |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Sep 21, 2005 4:51 pm Post subject: |
|
|
yeah it works that way, and you are crying to be hacked or at least exploited
see Script Security topic in FAQ forum _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
|