ToME: the Tales of Maj'Eyal
http://forums.te4.org/

Role of resolvers.lua in modules?
http://forums.te4.org/viewtopic.php?f=40&t=45695
Page 1 of 1

Author:  LeToucanHasArrived [ Wed Feb 17, 2016 8:19 am ]
Post subject:  Role of resolvers.lua in modules?

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!

Author:  darkgod [ Wed Feb 17, 2016 8:48 am ]
Post subject:  Re: Role of resolvers.lua in modules?

Resolvers basically are there to let you postpone some stuff in entities.
You *could* write a field like that in an entity:
Code:
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:
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.

Author:  LeToucanHasArrived [ Wed Feb 17, 2016 8:41 pm ]
Post subject:  Re: Role of resolvers.lua in modules?

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?

Author:  darkgod [ Wed Feb 17, 2016 10:44 pm ]
Post subject:  Re: Role of resolvers.lua in modules?

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 :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/