Page 1 of 1

Delays

Posted: Sun Aug 26, 2012 5:53 pm
by Kami
Heya, propably this is a pretty noobish question, but how can I delay the execution of a command?
Thank you :)

kami

Posted: Sun Aug 26, 2012 6:04 pm
by Tuck

Posted: Sun Aug 26, 2012 7:23 pm
by Kami
Thank you for the answer :)
I have this line:

Syntax: Select all

prot_delay = Timer(10.0, entity.SetPropInt("CBaseAnimating.m_nHitboxSet", 0))
prot_delay.start()


But it gives me this error:

The attachment error.jpg is no longer available

Posted: Sun Aug 26, 2012 7:26 pm
by Tuck
Thats because your using it the wrong way :)

Try this:

Syntax: Select all

prot_delay = Timer(10.0, entity.SetPropInt, ["CBaseAnimating.m_nHitboxSet", 0])
prot_delay.start()

Posted: Sun Aug 26, 2012 7:28 pm
by satoon101
You are executing the code directly instead of passing arguments.

Instead of:

Syntax: Select all

prot_delay = Timer(10.0, entity.SetPropInt("CBaseAnimating.m_nHitboxSet", 0))


Use:

Syntax: Select all

prot_delay = Timer(10.0, entity.SetPropInt, ("CBaseAnimating.m_nHitboxSet", 0))
Satoon

Posted: Sun Aug 26, 2012 7:34 pm
by Tuck
satoon101 i used [] because u wouldnt get strange problems using it that way, If people come back here to see what to do
(not saying your wrong just making sure people would notice the difference) :)

Syntax: Select all

Timer(10.0, FUNCTION, ("CBaseAnimating.m_nHitboxSet"))


would give this error for function that only accepts one argument
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python33\lib\threading.py", line 639, in _bootstrap_inner
self.run()
File "C:\Python33\lib\threading.py", line 825, in run
self.function(*self.args, **self.kwargs)
TypeError: FUNCTION() takes 1 positional argument but 27 were given

Posted: Sun Aug 26, 2012 7:59 pm
by satoon101
Well:

Syntax: Select all

("CBaseAnimating.m_nHitboxSet")
This is not a tuple:

Syntax: Select all

>>> type(("CBaseAnimating.m_nHitboxSet"))
<class 'str'>
>>> type(("CBaseAnimating.m_nHitboxSet", ))
<class 'tuple'>
So, you are basically passing a string, when you should be passing an iterable.

To make it a tuple, use the following:

Syntax: Select all

("CBaseAnimating.m_nHitboxSet", )
You can also use a list, as you have, but that really is not the proper way to do it.

Satoon

Posted: Mon Aug 27, 2012 4:27 am
by Tuck
Thanks for the explaination satoon was helpfull :)

Posted: Mon Aug 27, 2012 9:55 am
by Omega_K2
As I said be careful with the timers, if it happens to execute on mapchange (for player props for example), the server will crash :P