[NFP] Storing Tables on Objects as Properties

DeckerdJames

Warlord
Joined
Nov 1, 2019
Messages
235
For other Lua newbies like myself, I thought I could share this. You can save a table on an object that has the SetProperty function like this:

Code:
...code that sets up a valid Player named pPlayer..
then...
pPlayer:SetProperty("myDataTable", {})

But SetProperty has to be done from a GamePlay script to work. You can't set them from UI scripts.

Then you get it out like this
Code:
local dataTable:table = pPlayer:GetProperty("myDataTable")

As far as I could tell, you have to get the table out and make the changes you want. Then you can SetProperty the table again. I couldn't manipulate the table directly on the object, but my coding skills are not very extensive. Maybe, they do it this way, because otherwise, I could get around the inability to directly change data from the UI script side. I don't know.

So, I am brand new to Lua and Civ 6 modding, but this seems very flexible. I have been experimenting with it and you can nest tables into an object. I guess you can do anything you want with the table as long as it is a valid thing to do in Lua. Not sure about that. I think you can even put functions in a Lua table. I have not experimented with that yet, but I guess you could create custom functions for a series of objects, if you can do it in the Civ 6 modding enviroment, whether they are the same type of object or not. Sounds interesting though, if functions can be stored in the tables. I don't have a reason to try it yet. Maybe an AI engine could use that kind of ability.
 
Last edited:
Top Bottom