Getting a Lua script to load

isnorden

Amnesiac Modder
Joined
Jul 6, 2012
Messages
608
Location
Madison, Wisconsin, USA
Please forgive my painfully simple question, but ... how do you "tell" a mod to recognize and run a Lua script when it's needed? ModBuddy doesn't include any tools for making new scripts "visible", as far as I know. All I've done is included the Lua file in the .modinfo listing, like this:
Code:
  <Files>
    <File md5="81EF9C5A9A35FE4FF940DD005AF18468" import="1">Lua/city_pop_rules.lua</File>
    <File md5="1EB358F51441494FCD548D750E870E85" import="0">XML/GlobalDefines.xml</File>
    <File md5="746DBD3B0EA4CAC65F0FAA239F72D825" import="0">XML/gopachara.xml</File>
    <File md5="01337836E869347124F69EBF7A8D7F1A" import="0">XML/gopachara_update.xml</File>
    <File md5="D23E426E2573E01EB1A98B27913BC597" import="0">XML/sacred-cattle_fixes.xml</File>
    <File md5="24F1B3547C7517B5A9006356F45CAB86" import="0">XML/trait_tweaks.xml</File>
    <File md5="91C9F411C45E4F6768D2FE8C18269B95" import="0">XML/Worlds.xml</File>
  </Files>

Please let me know what I should have done; this is my first mod to use any Lua hacks.
 
See here - http://forums.civfanatics.com/showthread.php?t=487846

Specifically, under .lua files "Does this file contain methods registered by events within the file, or methods that are then executed directly during game startup?"

And then post #3

Note that for a Lua only InGameUIAddin you'll need to do the steps in the order 1, 2, 6, 3, 4, 5, 7
 
Thank you again; I'm still learning this stuff.
 
... how do you "tell" a mod to recognize and run a Lua script when it's needed?
whoward69's answer deals with how to get your Lua file to load. But I wonder if that's only part of your question?

Code:
print("Loading my file")

function OnPlayerDoTurn(iPlayer)
	print("Running OnPlayerDoTurn for " .. iPlayer)
end
GameEvents.PlayerDoTurn.Add(OnPlayerDoTurn)
The "naked" code (outside of the function) runs when the file loads. That includes the first print statement ("Loading my file") but also the Add command after the function. The Add method tells the dll to call the function OnPlayerDoTurn on every player turn (supplying the argument iPlayer). So you see "Running OnPlayerDoTurn... " each player turn.

Sorry if I'm answering something you already know...
 
Back
Top Bottom