Delays

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Delays

Postby Kami » Sun Aug 26, 2012 5:53 pm

Heya, propably this is a pretty noobish question, but how can I delay the execution of a command?
Thank you :)

kami
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 26, 2012 6:04 pm

-Tuck
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Sun Aug 26, 2012 7:23 pm

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
Attachments
error.jpg
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 26, 2012 7:26 pm

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()
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 26, 2012 7:28 pm

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
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 26, 2012 7:34 pm

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
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 26, 2012 7:59 pm

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
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Aug 27, 2012 4:27 am

Thanks for the explaination satoon was helpfull :)
-Tuck
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Mon Aug 27, 2012 9:55 am

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 18 guests