okay so to go off on my last post, since i really got into that one event

here's some stuff others might want to try
Code:
function popchange(a, b, c, d, e)
print(a);
print(b);
print(c);
print(d);
print(e);
print("population changed somewhere....");
end
Events.SerialEventCityPopulationChanged.Add( popchange );
here it's going to grab whatever default arguments gets passed to 'SerialEventCityPopulationChanged'. running the game on the first turn, it's just a few seconds and it shows that a-b-c-d are defined, while e is nil. so this event gets 4 variables passed to it.
luckily this event has some examples in the vanilla files:
Code:
function SetCitySize()
local iCitySize = Game.GetVariableCitySizeFromPopulation( g_iPopulation );
Events.SerialEventCityPopulationChanged( g_iHexX, g_iHexY, g_iPopulation, iCitySize );
end
Controls.CitySize_ButtonApply:RegisterCallback( Mouse.eLClick, SetCitySize );
not hard to guess what they mean, an x and y position, population and city size. problem here is that the x-y doesnt exactly correspond to what's shown on the game map.
this is where the 'ToGridFromHex' function is used. it seems like its an often used function, so again, i'm guessing there's a lot of events that pass grid coords that need to be converted, or vice versa with hex cords (there is a ToHexFromGrid).
then once converted there's other functions to pull plot info to get some more data (Map section) and there's plenty of examples to get yourself started in the vanilla files
in the end, the new code is now looking like this
Code:
function popchange(a, b, c, d)
--Events.SerialEventCityPopulationChanged( g_iHexX, g_iHexY, g_iPopulation, iCitySize );
--the example code used for reference
print(a);
print(b);
print(c);
print(d);
local hx, hy = ToGridFromHex( a, b );
print("hex x: " .. hx .. " hex y: " .. hy);
-- now the coords should match the new city coords pop change from 0 to 1
-- and any other population change
local plot = Map.GetPlot(hx, hy);
local city = plot:GetPlotCity();
print( "Pop change:\t" .. city:GetName() .. "\t" .. city:GetPopulation() );
--print("population changed somewhere....");
--commented this noob scripting line as there is plenty of better informed print statements above :)
end
Events.SerialEventCityPopulationChanged.Add( popchange );
so theres an event, a method at how to figure out what default values (i'm sure theres a proper term in lua lingo for those but i don't know lua at all so default arguments is what i put) are being passed to the function, and then a simple way to get extra relevant information on the event, and most of it is just copy / paste
whew that was fun
