View Full Version : Howto reload your lua code within the game


Onni
Oct 09, 2010, 12:27 AM
It's possible to reload your changed lua source code within the game (without exiting).


Start your Civ 5 game with your mod and also start your LiveTuner.
Make changes to your source code in ModBuddy.
Save and build your solution in ModBuddy.
In LiveTuners "Lua Console"-tab choose your mods thread(?). By default it reads "Main State", but choose the one that has your mods name.
Type the following command to the console at the bottom: include("your_mod_name_here").
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.

Start your Civ 5 game with your mod and also start your LiveTuner.
Create a new panel in LiveTuner. While creating it remember to choose your mods thread(?) from the list below the name line.
Choose your mods thread(?) from the drop down. If you don't see it then go back to step 2.
Rightclick the empty canvas and choose "new action control".
In the action part write your updated function.
Press test and if there are no errors press ok.
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.

Drog
Oct 16, 2010, 12:42 AM
Nice! Now if we can find how to reload xml...

eastwind
Nov 29, 2010, 07:14 PM
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.