Num of objects in GameInfo table (solved)

Infixo

Deity
Joined
Jan 9, 2016
Messages
4,034
Location
Warsaw
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!
 
Back
Top Bottom