Howto reload your lua code within the game

Onni

Chieftain
Joined
Oct 9, 2010
Messages
82
It's possible to reload your changed lua source code within the game (without exiting).

  1. Start your Civ 5 game with your mod and also start your LiveTuner.
  2. Make changes to your source code in ModBuddy.
  3. Save and build your solution in ModBuddy.
  4. In LiveTuners "Lua Console"-tab choose your mods thread(?). By default it reads "Main State", but choose the one that has your mods name.
  5. Type the following command to the console at the bottom: include("your_mod_name_here").
  6. Your new source code should now be active in the game.
-This applies only to lua files, not xml. Not sure yet how to do this for the UI-xml files?
-You have to be careful when you do this. When it re-reads your source it also does again everything you have written. So if you are e.g. registering to events then after this you have registered twice to all of those events.
-Also xml-instances should be reset before reloading or otherwise you might experience "ghost-elements". ;)

It's possible to update a single function using LiveTuner.
  1. Start your Civ 5 game with your mod and also start your LiveTuner.
  2. Create a new panel in LiveTuner. While creating it remember to choose your mods thread(?) from the list below the name line.
  3. Choose your mods thread(?) from the drop down. If you don't see it then go back to step 2.
  4. Rightclick the empty canvas and choose "new action control".
  5. In the action part write your updated function.
  6. Press test and if there are no errors press ok.
  7. Now press your newly created action button and your function should be immediately updated.

Even if it takes some time and thought to do this I think it's worth it. At best after every lua change I just build my solution in ModBuddy, typed the include command in LiveTuner and I could see my mod updating immediately after.
 
If all you are doing is making a new map script then each time you start a new game the map script is rerun, so you don't need to use LiveTuner, you can simply "Exit to Main", save changes to the map script and go through the "Set Up Game" dialog again to test your changes.

That probably goes without saying (but I decided to say it anyway just in case).

Another hint for first-time modders getting their feet wet by doing a map script: if your map script fails partway through due to a runtime error, the usual result seems to be that the game loads, but as soon as you hit "Begin Your Journey" you get the big "Defeat" popup.
 
Back
Top Bottom