Why GameInfoTypes["..."] Does Not Equal player:GetCivilizationType()?

g02703

Chieftain
Joined
Apr 2, 2016
Messages
33
I am looking at the lua console at FireTuner.

local player = Players[playerId] -- as usual in an event handler

print(GameInfoTypes["CIVILIZATION_MY_SPONSOR"]) -- outputs 15
print(player:GetCivilizationType()) -- also outputs 15.
print(tostring(GameInfoTypes["CIVILIZATION_MY_SPONSOR"] == player:GetCivlizationType())) -- outputs false. Doesn't make sense.

But (player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MY_SPONSOR"]) evaluates to false? Why? Why is 15 not equal to 15?

What I want to do in a lua "event handler" is to check whether the current player's civilization is of a particular faction. If that's true, then I'll award that player something. What am I doing wrong?
 
Does the following return false as well?
Code:
GameInfo.Civilizations["CIVILIZTION_MY_SPONSOR"].ID == player:GetCivilizationType()

I was going to say you may have been comparing a string of "15" to the number 15 but the paren count is correct so that isn't the problem.
 
GameInfo.Civilizations["CIVILIZTION_MY_SPONSOR"].ID == player:GetCivilizationType() returns false as well, even if both of their print(...) say 15.

According to the Civ5 Lua Documentation, player:GetCivilizationType() actually returns an integer, although the documented return type is CivilizationType (only for convenience of development, they say). GameInfoTypes["UNIQUE_IDENTIFIER"] also returns an integer, and so does GameInfo.Civilization["CIVILIZATION_MY_SPONSOR"].ID.

For some reason, do the surrounding parentheses mess up our results? From looking at a lot of sample lua code, they do not enclose boolean expressions with parentheses.

Another theory I have is that GameInfoTypes["UNIQUE_IDENTIFIER"] and player:GetCivilizationType() do NOT actually return a primitive value (like an integer that we thing both of them return), despite what the Civ5 documentation says. They might actually be objects whose values are semantically equivalent, but reside in different locations in memory, hence, they're not equal. And somehow, lua knows how to automatically output them to string when an argument of print() - which explains why they have the exact same output.
 
I'll look at my code again for that typo. I typed it here again instead of copy-paste from code. I will leave the typo as-is in the first post for reference. I will come back later to update.

But shouldn't have I received an error? I'm accustomed for compilers and runtime to tell me when I'm attempting to access a non-existent function or a property of an object. Maybe then lua just returns false when this happens? I don't know.
 
Yes, indeed. The functionality itself is working properly though, just checked and I'm using it in exactly the same way in my Awesome Sponsors Mod:

Code:
if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_CHUNGSU"] then

So if you're really making these 3 print-statements one after the other without accidentially redefining the player-variable (I know, I know... I'm grasping for straws here. :D) No idea what's wrong then.

As far as I can tell it can't be what you're assuming above though. Lua doesn't work with variable types, it works with value types, so 15 is always equal 15 as both are automatically of type number when they're returned.
 
@Ryika - Indeed, I did have an error in variable spelling.

local civId = GameInfoTypes["CIVILIZATION_MY_SPONSOR"]; -- let's say this is 15
local playerCivId = player:GetCivilizationType(); -- this is also 15.

local areEqual = civId == playerCivvvvId -- just exaggerated the typo so all will see

playerCivvvId is not defined, so strangely, in a way, it definitely does not equal civId. I would have expected a build error, but I guess that's not how lua works.
 
Yeah, variables that don't have a value are simply returned as nil and don't give an error.
I guess that's one of the small problems of not actually forcing variables to be initialized.
 
Top Bottom