DeckerdJames
Prince
- Joined
- Nov 1, 2019
- Messages
- 340
For context, I only made one simple mod for Civ 6, but I believe that I had learned how to set custom properties on the objects in Lua Code. I am trying to figure out if they implemented that in Civ 7. I didn't get much of a chance to do much with the discovery in Civ 6 but I will include what I learned.
This is the old thread from the Civ 6 forums that is relevant.
Storing Tables on Objects as Properties
Being able to store custom data onto something like a valid "player" object in the form of custom properties seemed very important, and I think that if I recall correctly, those custom properties are saved in the save file. I would have to double check. Also, some game objects such as your capital city, which can never be razed, would be useful for storing data that persists the whole game for each civilization. I don't remember if the manager objects, such as the unit manager, had the SetProperty method, but some of the game's singleton objects like the unit manager could have hosted custom data that would be stored the whole game if the Unit manager is never destroyed and recreated. (I don't think it is, but it might recreate some things when the save game loads, so I am not sure)
So, in Civ 6, you had to create the property through a SetProperty method.
The first parameter in quotes is the name of your custom property and the second parameter is a table which you have created. In the above example, it is just an empty table, but I assume that could be a variable name that references a table you created in within the scope of the currently running game play script.
An example might be a game play script that triggers to cause the collection of some data about the geography around a particular unit. That data is gathered into a table. You then save it on that unit with the SetProperty method. I thought this would be a major key to data organization and lead to more advanced data collection and storage. That could even mean a better AI system.
I never got a chance to do all the experimentation with it that I wanted. I wasn't able to check if all the objects such as units, cities, etc. had the SetProperty method, but I think so. Now in Civ 6, it was Lua so you could store anything in your table that was legal in Lua, and I think you could set as many custom properties on an object as LUA would allow because I assume the custom properties are also stored in a table. (everything is a table in Lua I think)
Then in another game play script that is triggered for some reason you might retrieve that custom property with:
Then you make changes or decisions based on that data and since you are in a game play script you could set the property again with an updated table. On the other hand, if you retrieved that table from a UI script, you could use or change the data for your UI but you could not set the property back from a UI script. That keeps the UI context as a "view only" of the data.
Now, onto Civ 7. I see that they are using javascript in 7. i think I like it, but I have not had a chance to figure out how to make a game play script yet. I see that the UI scripts have been generously shared. I could see that the objects they have exposed include the private data, so I think that means they have given us full control over the UI scripts, but I am still locating non-UI scripts.
Has anyone created game play scripts yet and is there a way to save custom properties on the objects such as a valid "player" object as in Civ 7? Has anyone had any success with that?
edit:whoops. I didn't mean this for the tutorials section necessarily, and I am not sure if that is a good place. Please move it if appropriate.
This is the old thread from the Civ 6 forums that is relevant.
Storing Tables on Objects as Properties
Being able to store custom data onto something like a valid "player" object in the form of custom properties seemed very important, and I think that if I recall correctly, those custom properties are saved in the save file. I would have to double check. Also, some game objects such as your capital city, which can never be razed, would be useful for storing data that persists the whole game for each civilization. I don't remember if the manager objects, such as the unit manager, had the SetProperty method, but some of the game's singleton objects like the unit manager could have hosted custom data that would be stored the whole game if the Unit manager is never destroyed and recreated. (I don't think it is, but it might recreate some things when the save game loads, so I am not sure)
So, in Civ 6, you had to create the property through a SetProperty method.
Code:
Code:
...suppose there is code that sets up a valid Player named pPlayer..
then...
pPlayer:SetProperty("myDataTable", {})
The first parameter in quotes is the name of your custom property and the second parameter is a table which you have created. In the above example, it is just an empty table, but I assume that could be a variable name that references a table you created in within the scope of the currently running game play script.
An example might be a game play script that triggers to cause the collection of some data about the geography around a particular unit. That data is gathered into a table. You then save it on that unit with the SetProperty method. I thought this would be a major key to data organization and lead to more advanced data collection and storage. That could even mean a better AI system.
I never got a chance to do all the experimentation with it that I wanted. I wasn't able to check if all the objects such as units, cities, etc. had the SetProperty method, but I think so. Now in Civ 6, it was Lua so you could store anything in your table that was legal in Lua, and I think you could set as many custom properties on an object as LUA would allow because I assume the custom properties are also stored in a table. (everything is a table in Lua I think)
Then in another game play script that is triggered for some reason you might retrieve that custom property with:
Code:
local dataTable:table = pPlayer:GetProperty("myDataTable")
Now, onto Civ 7. I see that they are using javascript in 7. i think I like it, but I have not had a chance to figure out how to make a game play script yet. I see that the UI scripts have been generously shared. I could see that the objects they have exposed include the private data, so I think that means they have given us full control over the UI scripts, but I am still locating non-UI scripts.
Has anyone created game play scripts yet and is there a way to save custom properties on the objects such as a valid "player" object as in Civ 7? Has anyone had any success with that?
edit:whoops. I didn't mean this for the tutorials section necessarily, and I am not sure if that is a good place. Please move it if appropriate.
Last edited: