Forum

> > CS2D > Scripts > 0 seconds delay loops
Forums overviewCS2D overview Scripts overviewLog in to reply

English 0 seconds delay loops

6 replies
To the start Previous 1 Next To the start

old 0 seconds delay loops

Mami Tomoe
User Off Offline

Quote
Hey, I'm not very experienced with mapping's resource management, and I came here to ask a couple questions:

1. Can using a 0 sec delay to activate another 0 sec delay (and repeat that as a loop) cause any issues?
2. Should #1 be placed in Lua instead (such as ms100 hook)?
3. How does it compare to the ms100 hook in terms of resources?
4. How fast is it looping?
5. How fast are delays triggered in general? (Could be the same as #4)
6. Should I use it to call a trigger_if (for a math.random)?

Thanks!

old Re: 0 seconds delay loops

DC
Admin Off Offline

Quote
In general, infinite entity trigger loops (and also infinite loops in scripts) are something that must be avoided at all cost. Having an infinite trigger loop would make CS2D crash in some cases (depending on the type of entities involved).

This is because - like user Devil-Thanh pointed out correctly - CS2D is single threaded and it would keep updating the trigger stuff forever and couldn't update anything else anymore (the rest of the game).

cs2d entity trigger_delay is a special case because when you trigger a trigger delay it will only set a timer. The actual trigger action will be executed one frame earlier (in case of 0 delay or only a few ms delay) or later. This allows CS2D to move on instead of staying in a trigger loop. (I actually didn't test that but I had a short look at the code and it looks like it should behave like that)

1. With cs2d entity trigger_delay? You can do that (see explanation above) but depending on what you're doing it can be quite expensive. Especially when you run stuff which needs to be sent to clients. Then this would cause a lot of additional network traffic. If possible try to use a higher delay. You can also use fractions of a second. e.g. 0.2 for 200 ms = 5 times per second.

2. Depends on what you want to do. If other Lua code is involved anyway (via trigger_if) I would recommend to do everything in Lua instead of using entities.

3.
• trigger_delay with 0 delay should be executed every frame (if it directly triggers itself or another 0 delay trigger_delay again) = ~60 times per second (comparable to cs2d lua hook always which executes about 50 times per second for backward compatibility reasons)

• cs2d lua hook ms100 is executed ~10 times a seconds. Way less frequently and therefore it costs less resources.

4. See above explanations. There is no real looping! CS2D is single threaded. So if you want to execute something over a longer period of game play time you can do that only as fast as CS2Ds mainloop executes and that is capped by the FPS.

5. See 3/4

6. See 2. If you want to do Lua stuff you should probably just do the whole thing in Lua. It's cleaner. Performance wise there probably isn't a huge difference.


Hope that helps. If it doesn't you should maybe tell us what you plan to do
edited 1×, last 18.04.19 07:51:35 pm

old Re: 0 seconds delay loops

Mami Tomoe
User Off Offline

Quote
Delay 1 calls Delay 2

Delay 2 calls Delay 1 + If

If checks a math.random(1,5)
√ Enable or disable light source
× Do nothing

That's to make a flickering light source.

Though I didn't know delays can use floats... Gonna give it a go!

old Re: 0 seconds delay loops

DC
Admin Off Offline

Quote
I see. Should be okay to do this with entities only. Shouldn't really make a difference performance wise.

Note that this causes internet traffic though if you play a map with this online. Each time the light state is changed via triggering. It's okay with one light but if you have many flickering lights which flicker with a high frequency then this may become a problem ( = quite a lot of additional traffic just for a simple effect).
edited 1×, last 18.04.19 08:07:04 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview