Page 1 of 1

Role of resolvers.lua in modules?

Posted: Wed Feb 17, 2016 8:19 am
by LeToucanHasArrived
Hi all,

I'm trying to dig into T-Engine4 module development by hacking together stuff from various open source modules, but I also want to understand what the API's actually do. I think I'm building up intuition about most of the files but I am totally stumped by the resolvers.lua file and resolvers in general. Can someone help me understand what are resolvers and how they work?

Thanks!

Re: Role of resolvers.lua in modules?

Posted: Wed Feb 17, 2016 8:48 am
by darkgod
Resolvers basically are there to let you postpone some stuff in entities.
You *could* write a field like that in an entity:

Code: Select all

foo = rng.range(1,10)
But the call to rng.range would happen when the entity files is loaded and thus set the value in stone for all entities cloned from it.
If instead you used

Code: Select all

foo = resolvers.rngrange(1, 10)
Then it would take its value only when the entity has been cloned, making sure every clone has its own random value.

Re: Role of resolvers.lua in modules?

Posted: Wed Feb 17, 2016 8:41 pm
by LeToucanHasArrived
Thanks! So a resolver is just a function you call as part of loading an entity right? Does the engine itself have any concept of resolvers?

Re: Role of resolvers.lua in modules?

Posted: Wed Feb 17, 2016 10:44 pm
by darkgod
Yes it does, a resolver function must return a table taht has a field "__resolver" set to a unique name (most of the time the same as the name of the resolver).
The engine will look for this name in the resolvers.calc table when it needs to actually resolve the entity.
Just take a look a the existing resolvers it should be self evident now :)