Pass data to CityView.lua

killmeplease

Mk Z on Steam
Joined
Nov 22, 2007
Messages
2,795
Location
Samara
In my mod one of the files (lets call it file1) is set to be an InGameUIAddin to provide an entry point. it uses another file (lets call it file2) where some global variable V is declared, it is then set to some value in file1.
now i include file2 in the modded CityView.lua and try to read the value of V but its nil. it seems CityView makes its own V which isnt visible for file1 and otherwise.
so, is there a way to pass some data to CityView (except for SetScriptData)?
 
Welcome to the weird and wacky world that is Firaxis' extensions to Lua.

The include() function is a Firaxis addition - it literally includes the contents of the file into the current context (as if you have copy/pasted it) so each context ends up with its own copy of any functions and variables within the included file - they are NOT shared. Hence why setting a value in one context has no effect on another context.

To share data, you'll need to share a table/hash and put data into it - you can either do this by passing one via LuaEvents or use MapModData (which is a table that just happens to be (mainly) unused by Firaxis and available to all contexts.

See also
http://forums.civfanatics.com/showthread.php?t=529177
http://forums.civfanatics.com/showthread.php?t=517232
http://forums.civfanatics.com/showthread.php?t=449223
http://forums.civfanatics.com/showthread.php?t=484069
and probably others (JFGI: Civ 5 "MapModData")
 
Back
Top Bottom