GameInfo.Units is type userdata

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
Code:
> print(type(    GameInfo    ))
 EaMain: table
> print(type(    GameInfo.Units    ))
 EaMain: userdata
> print(type(    GameInfo.Units()    ))
 EaMain: function
> print(type(    GameInfo.Units[1]    ))
 EaMain: table

This has been puzzling me for a while. For one thing, there is no other Lua variable type where you can use both "()" and "[]" after the variable. Also, accessing something like GameInfo.Units["UNIT_WARRIOR"].ID is very slow, about 17x slower than looking up the same info in a simple Lua table using GameInfoTypes["UNIT_WARRIOR"]. Even though the first looks like a table access, it's really passing your request to some C++ method (the GameInfo.Units part), which then passes you a table. Apparently this isn't very fast (it's not looking up the value in the DB! that would be much much slower). The iterator function you get from GameInfo.Units() is even worse -- it's about 70x slower than setting up your own iterator in Lua. (See speed tests here; this is not an issue unless you are checking something 100s of times a turn, but keep it in mind if you are doing some lookup for every unit or every plot each turn.)

Apologies for the very technical post. Carry on now...
 
At least until the formula one driver actually presses the gas pedal. :lol:

(I know that you where only joking but I couldn't help myself. :mischief:)
 
I'll keep this in mind when I go through optimizing Sparta. Every little bit helps.
 
At least until the formula one driver actually presses the gas pedal. :lol:

(I know that you where only joking but I couldn't help myself. :mischief:)

But if you put the F1 driver in the Civic and the Civic driver in the F1 car, then the Civic WILL be faster. Which just goes to prove that it's not the capabilities/speed of the cars (programming languages) which are important but the relevant skills of the drivers (programmers)
 
Back
Top Bottom