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 

timer and timer id

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
SaPrOuZy
Halfop


Joined: 24 Mar 2004
Posts: 75
Location: Lebanon

PostPosted: Tue Sep 20, 2005 3:59 am    Post subject: timer and timer id Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Sep 20, 2005 4:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SaPrOuZy
Halfop


Joined: 24 Mar 2004
Posts: 75
Location: Lebanon

PostPosted: Tue Sep 20, 2005 4:34 am    Post subject: Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Sep 21, 2005 12:41 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SaPrOuZy
Halfop


Joined: 24 Mar 2004
Posts: 75
Location: Lebanon

PostPosted: Wed Sep 21, 2005 12:51 am    Post subject: Reply with quote

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
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Sep 21, 2005 1:09 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Sep 21, 2005 3:07 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Sep 21, 2005 4:38 pm    Post subject: Reply with quote

sorry sorry sorry for forgetting the "" quotes, but with these it works... this time tested Razz.

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
View user's profile Send private message MSN Messenger
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Sep 21, 2005 4:51 pm    Post subject: Reply with quote

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

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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