Fandom

Civilization

Comments0

How to use Lua flies?

Oldag07 October 3, 2015 User blog:Oldag07

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

I copied these two messages that are meant to explain how to use the lua language on this site. This was written for future reference.

Becer's comment

Hey there, I'd be happy to tell you about Lua powered templates and how to work them, the best way to do that would be to contact me using one of the methods listed on my profile so I could answer your questions directly, or you can always ask them here like you did of course.

Otherwise documentation on the way this new templating method works can be found here.

Here are some useful links within this wiki to understand what's going on under the hood:

I hope this helped, please don't hesitate to ask more questions. --Becer (talk) 02:10, September 30, 2015 (UTC)

ZeroOne's message

The story behind this setup is that User:Becer took the Beyond Earth XML files that contain all the game data, converted them to Lua files, and uploaded them into this wiki. We have then created templates that access those data files and produce information that's 100% accurate and consistent with the game. For Beyond Earth, those templates are defined in the Module:Data/CivBE file.

For the {{Sponsor (CivBE)}} template that you mentioned, the code is produced by the function that starts with the row "function p.GetSponsorPage(frame, articlename)". It then uses the page name to find the correct data from the Module:Data/CivBE/Base/Civilizations file, which is one of those that Becer generated and uploaded. So for example, if the page is called American Reclamation Corporation (CivBE), the template extracts the string "American Reclamation Corporation" and then goes to find the Sponsor whose Description is "American Reclamation Corporation" in Module:Data/CivBE/Base/Civilizations: "CIVILIZATION_ARC" in this case.

Besides having 100% accurate and correct information, the other idea behind using Lua modules is that the data only exists in one place. Previously if we wanted to, say, create a list of units, we would've had to duplicate information both on the list page and the individual unit pages. One might also want to refer to some unit stats in other places, and all this duplication makes it really hard to keep the wiki up to date and is very error prone. For example, when a patch adjusts a unit's strength, do we want to update that piece of information to just one place, or do we want to hunt down all the places where that value might have been used? Obviously it's easier to have all the information in one place.

A drawback that you noticed is that it's definitely not easy for new editors to find their way around the Lua template system. However, we figured that once the templates are done, they don't need to be edited anyway. Unfortunately the XML database format of Beyond Earth is not a very accessible one, so it takes considerable time (and some skills) to create the advanced templates that may have a dozen different values from different database tables.

Our first project with Lua, when it was just enabled in the wiki, was Civilization Revolution 2 and its templates. The templates are defined at Module:Data/CivRev2 and the data comes from modules such as Module:Data/CivRev2/Civilizations and Module:Data/CivRev2/Units. Then there's {{Unit (CivRev2)}}, pages such as Cannon (CivRev2) and the List of units in CivRev2. You'll notice that the format of those Lua modules is much more readable than the Beyond Earth module format. This is because of the fact that we created the modules by hand, i.e. by reading the in-game Civilopedia and then typing in the info as we saw fit. No confusing databases to play with.

Anyway... If one is going to learn programming (and I hope I've at least sparked an interest n that in you!), Lua is a relatively easy language to start with. I've written some instructions into the Forum: General Discussion about this Wiki board > Testing Lua functions. Besides that, I'm sure googling for Lua tutorials will get you started too. And here's a fun fact: Civilization V and Beyond Earth mods are written using Lua too! See the Modding (Civ5) page, it has some links.

When I learn a new programming language, I tend to start with just modifying some existing pieces of code and seeing what happens. I'm not sure if we've got some Lua sandbox to play with, but if there isn't, feel free to create one. :)

ZeroOne (talk) 22:46, October 2, 2015 (UTC)

Also on Fandom

Random Wiki