Forum

> > CS2D > Scripts > Hook_always VS timer(1)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hook_always VS timer(1)

1 reply
To the start Previous 1 Next To the start

old Hook_always VS timer(1)

Apache uwu
User Off Offline

Quote
Hook always polls on every frame, which is expected to be 50 times per second. 50/s However timer is polled on the interval passed which is 1 millisecond. 1000/s

Timer is obviously the faster one, but since it's not a hook it must be that it's NOT on the same cs2d state as always, or it's engulfing always--which is not likely because timer is a bit off sync than the other hooks as well as functions.

Since that is the case does opening multiple timers is the same as opening multiple states ... right? If that is also true then is it possible that the functions called from timers are also brought onto the newly created state?

old Re: Hook_always VS timer(1)

Lee
Moderator Off Offline

Quote
Hmm, each state should theoretically have its own global space that's independent of the others, since this is probably not the case, I don't think timer spawns states. Here's a quick and easy way to test whether they do or not.

1
2
3
4
5
6
#include "lua.h"

int getstate(void* l){
	lua_pushinteger(l, (int)l);
	return 1;
}

Compile using

1
gcc -L"dir/to/lua/lib" -llua51 -I"dir/to/lua/include" -o getstate.dll getstate.c

And load into lua using
1
2
3
getstate = package.loadlib("getstate.dll", "getstate")

pointer = getstate() -- this will return the pointer to the current lua state. If timers spawn states, then getstate() within each timer callback should be different as different states are invoking the getstate function each time, meaning that the pointer should also be different.

Remember that a lua state is nothing more than the root node of the execution scope. Think closures, where the lua state is the top level (it provides the _G table) and is like the core of an onion, and each successive level is like a single layer over the previous closure.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview