Is there an easy way to get a number of objects kept in a specific GameInfo table without the use of for loop? I.e. I wanna know how many Civics are in the game, so what to do with GameInfo.Civics?
not sure if the table.count(TableName) method will work on GameInfo.X() since the GameInfos are only sorta-kinda lua tables. The # method for an lua table-length only works on the array-portion of an lua table, so I'm not sure how it will result if you tried something like
Code:
local tTable = GameInfo.Civics()
local iLength = #tTable
Since the length of Database tables will not change during a game-session, you can always fall back on using a method like
Code:
local iNumCivics = 0
for row in GameInfo.Civics() do
iNumCivics = iNumCivics + 1
end
This would cache the number of Civics in the database into variable iNumCivics at game loading, so you would never need to run through the table-loop again for the rest of that game-session. Your lua code can then just refer to this cached data as needed.
edit -- and you should check my spelling of stuff too since I just saw three different typos in the original text I posted.
@LeeS GameInfo.Civics() is a function (iterator, actually), so # doesn't work. And GameInfo.Civics is userdata but it seems that # actually works for it! Yep, #GameInfo.Civics is 51, #GameInfo.Features is 18, etc. I don't know why I have not checked it earlier Anyway, thanks to your post I did, so thx!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.