• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Lua problems

Nitram15

Pro Libertate!
Joined
Sep 15, 2009
Messages
1,855
Location
Hungary
2 years gone since Kael's Guide, and loads of things has changed. After hours of searching for an answer, I couldn't get even the simplest of Lua script into the game: the simple clock. I understand Lua, there's no problem with its mechanism, I've just had to learn its syntax, since I used Python before. But I can't understand the way Civ 5 treats Lua scripts. I have a Lua script containing the following code:
Code:
ContextPtr:SetUpdate(function()
	local t = os.date("%I:%M");
	Controls.ClockLabel:SetString(t);
end);
Which I assume to be a working one, that's why Kael has written such a code.
And of course I've done the XML parts, which controls the label's position on the screen:

Code:
<Context ColorSet="Beige_Black" Font="TwCenMT20" FontStyle="Shadow" >
	<Label Anchor="C,T" Offset="0,10" Font="TwCenMT20" ColorSet="Beige_Black_Alpha" FontStyle="Shadow" ID="ClockLabel"/>
</Context>
Again, the same code by Kael. Seems quite easy, and it went smoothly for me as well. And the last part was well-known for me, for I've done quite a lot Civ 5 XML modding before, so when Kael wrote about the Actions part, and the Content part, I knew what to do. Or at least, I thought so.

So I added an action for clock.xml (the second code, obviously), set it for OnModActivated event, and UpdateDatabase action.
Then tried to add a content with a type of InGameUIAddin, then for both Name and Description, I wrote 'clock', and finally, when I tried to select clock.lua from the drop-down menu, clock.xml showed up instead. I selected that one, then clicked OK. I renamed clock.xml to clock.lua under the 'file' column then, built the solution, built the mod, then started the game, selected the mod, and voilà!, nothing happened.

I've tried several other methods after that failure, importing the lua file to the VFS, didn't work either. I honestly spent hours to work out a solution, yet I couldn't. I hope someone can help me, for I'm confused totally... :confused:
 
2 years gone since Kael's Guide, and loads of things has changed. After hours of searching for an answer, I couldn't get even the simplest of Lua script into the game: the simple clock. I understand Lua, there's no problem with its mechanism, I've just had to learn its syntax, since I used Python before. But I can't understand the way Civ 5 treats Lua scripts. I have a Lua script containing the following code:
Code:
ContextPtr:SetUpdate(function()
	local t = os.date("%I:%M");
	Controls.ClockLabel:SetString(t);
end);
Which I assume to be a working one, that's why Kael has written such a code.
It's SetText() not SetString(), so the Lua will fail to "compile" and hence fail to load.

And of course I've done the XML parts, which controls the label's position on the screen:

Code:
<Context ColorSet="Beige_Black" Font="TwCenMT20" FontStyle="Shadow" >
	<Label Anchor="C,T" Offset="0,10" Font="TwCenMT20" ColorSet="Beige_Black_Alpha" FontStyle="Shadow" ID="ClockLabel"/>
</Context>
Again, the same code by Kael. Seems quite easy, and it went smoothly for me as well. And the last part was well-known for me, for I've done quite a lot Civ 5 XML modding before, so when Kael wrote about the Actions part, and the Content part, I knew what to do. Or at least, I thought so.

So I added an action for clock.xml (the second code, obviously), set it for OnModActivated event, and UpdateDatabase action.
OnModActivated->UpdateDatabase is ONLY for XML that updates the database (these will always have a <GameData> root element - just remove this entry from your mod

Then tried to add a content with a type of InGameUIAddin, then for both Name and Description, I wrote 'clock', and finally, when I tried to select clock.lua from the drop-down menu, clock.xml showed up instead. I selected that one, then clicked OK. I renamed clock.xml to clock.lua under the 'file' column then,
For InGameUIAddin it doesn't actually matter if you select the xml or lua file - either will work.

built the solution, built the mod, then started the game, selected the mod, and voilà!, nothing happened.
Because of the syntax error in your lua file (see above)

I've tried several other methods after that failure, importing the lua file to the VFS, didn't work either.
Only set VFS=true for UI xml/lua files that are replacing parts of the standard UI, never for additions with InGameUIAddin entries

I honestly spent hours to work out a solution, yet I couldn't. I hope someone can help me, for I'm confused totally... :confused:

Start with Part 1 here http://forums.civfanatics.com/showthread.php?t=461552

HTH

W
 
Then ModBuddy should inform me somehow, that it failed to compile, but nothing told me about it...
Anyway, thank you.:)

ModBuddy won't know - it's not until it's loaded in game that the error will show.

In config.ini enable logging via "LoggingEnabled = 1" and then all your errors will appear in logs/lua.log (and also database.log and xml.log)
 
ModBuddy won't know - it's not until it's loaded in game that the error will show.

In config.ini enable logging via "LoggingEnabled = 1" and then all your errors will appear in logs/lua.log (and also database.log and xml.log)

I see. Thank you sooooo much!!! :)
 
Back
Top Bottom