Table data types

qqqbbb

Prince
Joined
Sep 25, 2010
Messages
530
Why does this code not print anything?
Code:
	for PromotionsRow in GameInfo.UnitPromotions() do
		for k,v in pairs(PromotionsRow) do
			if type(v) == number and v > 0 then
				print(PromotionsRow.Type,k) 
			end
		end
	end
 
The lua demo page will help to a certain degree:
Code:
local iTest = 1
if type(iTest) == number then
   print("iTest is a number")
end
results in an empy 'output screen'.

Code:
local iTest = 1
if type(iTest) == "number" then
   print("iTest is a number")
end
results in an 'output screen' of
Code:
iTest is a number
Your basic problem is that you are testing against a variable called number which has never been initialized and therefore is 'nil'. 'v' in your code-construct will never be evaluated as both 'nil' and greater than '0'.

The type(X) function in lua gives a string value, and therefore all evaluations against it must be stated as string values. (ie, "number" instead of number)

-----------------------------------------------------------------------------------------------

You could initialize variable number, as in
Code:
local number = "number"
but that wouldn't be any easier than just using "number" as the value to evaluate against in your code.

--------------------------------------------------------------------------------------------------

Also, not sure why you are trying to iterate through each and every column in each and every row in the UnitPromotions table. There may be a more efficient way of doing whatever it is you really want to accomplish.
 
Thanks
Also, not sure why you are trying to iterate through each and every column in each and every row in the UnitPromotions table. There may be a more efficient way of doing whatever it is you really want to accomplish.
I just want to know which promotion uses which column.
 
Scratch that! I a) mistyped it and b) was considering custom database tables where the default values are not 0/false ... which is not something that corners the core database tables greatly
 
Back
Top Bottom