cyclic includes...

lemmy101

Emperor
Joined
Apr 10, 2006
Messages
1,064
I've read that 'requires' needs a complete path to the lua file, which may cause problems in the Civ 5 environment. I've not tested requires myself, but notice it's not used anywhere in the Civ 5 lua code base or in other modder's lua I've seen. If it's just as simple as doing requires(blah) then I apologize for the redundant post.

Anyway here's something I've used to avoid include files being included more than once, to allow two files to reference eachother:

ISCity.lua
Code:
if ISCity ~= nil then
	return ISCity;
end

ISCity = {};

include ("ISBaseObject")
include ("ISReligion")

...

ISReligion.lua
Code:
if ISReligion~= nil then
	return ISReligion;
end

ISReligion= {};

include ("ISBaseObject")
include ("ISCity")

...

This will allow both files to reference each other and access each others contents, without infinitely including each other to the point of an error.

If you've got a 'too many chunks' error at some point, this is a very probable cause.

It will also stop the files being processed multiple times if multiple different files include them. So will stop you getting multiple event adds or data resetting on each include (unless it is cross Lua state boundaries, in which case you usually *want* it to include again anyway)

To reinclude the file in the lua console, just set ISCity = nil or whatever before you do the include.
 
Back
Top Bottom