Issue with Lua Function Parameters

Fluffins

Chieftain
Joined
Jul 13, 2017
Messages
6
I don't know if I'm just being an idiot (very possible) or if some of these function parameters are dyslexic.

From what I can tell using print (and looking at the MapGen scripts for some parameter guidance) Map:GetPlotXY() has the x and y flipped and Map:GetPlot() is just broken.

Lua script to be included into a temp mod like usual and recommended duel size map with no barbs or city states and a settler tier ai. Logs at the end of player turns only.

Code:
local Settler = "UNIT_SETTLER"
function BackwardsParameters(playerID)
    if (playerID ~= 0) then return end                                    -- Ignore AIs
    local playerUnits = Players[playerID]:GetUnits()
    local plot_One, plot_Two, plot_Three, plot_Four
    local plot_X, plot_Y
    local unit_Main, unit_X, unit_Y
    local plotTerrain
    local unitTypeName
    for i, unit_Main in playerUnits:Members() do
        if (unit_Main ~= nil) then
            unitTypeName = UnitManager.GetTypeName(unit_Main);
            if (unitTypeName == ("LOC_" .. Settler .. "_NAME")) then
                unit_X = unit_Main:GetX()                                -- These are fine according to debug tooltips
                unit_Y = unit_Main:GetY()                                -- These are fine according to debug tooltips
                print("Unit Found:\t\t\t\t\t" .. tostring(unitTypeName))
                print("Unit X:\t\t\t\t\t\t" .. tostring(unit_X))
                print("Unit Y:\t\t\t\t\t\t" .. tostring(unit_Y))
                plot_One    = Map:GetPlotXY(unit_X, unit_Y)                -- How it should work
                plot_Two    = Map:GetPlotXY(unit_Y, unit_X)                -- How it actually works
                plot_Three    = Map:GetPlot(unit_X, unit_Y)                -- 0s the 1st parameter and possibly backwards too
                plot_Four    = Map:GetPlot(unit_Y, unit_X)                -- 0s the 1st parameter and possibly backwards too
                print("=-= GetPlotXY =-=")
                if (plot_One ~= nil) then
                    print("======= 1 =======")
                    plotTerrain = plot_One:GetTerrainType()
                    plot_X = plot_One:GetX()
                    plot_Y = plot_One:GetY()
                    print("\tMapPlot X:\t\t\t\t\t" .. tostring(plot_X))
                    print("\tMapPlot Y:\t\t\t\t\t" .. tostring(plot_Y))
                    print("\tplotTerrain.Name:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Name))
                    print("\tplotTerrain.Index:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Index))
                    print("\tplotTerrain.Water:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Water))
                    print("\tplotTerrain.ShallowWater:\t"..tostring(GameInfo.Terrains[plotTerrain].ShallowWater))
                    print("=================")
                else
                    print("======= 1 =======")
                    print("\tplot_One = nil")
                    print("=================")
                end
                if (plot_Two ~= nil) then
                    print("======= 2 =======")
                    plotTerrain = plot_Two:GetTerrainType()
                    plot_X = plot_Two:GetX()
                    plot_Y = plot_Two:GetY()
                    print("\tMapPlot X:\t\t\t\t\t" .. tostring(plot_X))
                    print("\tMapPlot Y:\t\t\t\t\t" .. tostring(plot_Y))
                    print("\tplotTerrain.Name:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Name))
                    print("\tplotTerrain.Index:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Index))
                    print("\tplotTerrain.Water:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Water))
                    print("\tplotTerrain.ShallowWater:\t"..tostring(GameInfo.Terrains[plotTerrain].ShallowWater))
                    print("=================")
                else
                    print("======= 2 =======")
                    print("\tplot_Two = nil")
                    print("=================")
                end
                print("=-=- GetPlot -=-=")
                if (plot_Three ~= nil) then
                    print("======= 3 =======")
                    plotTerrain = plot_Three:GetTerrainType()
                    plot_X = plot_Three:GetX()
                    plot_Y = plot_Three:GetY()
                    print("\tMapPlot X:\t\t\t\t\t" .. tostring(plot_X))
                    print("\tMapPlot Y:\t\t\t\t\t" .. tostring(plot_Y))
                    print("\tplotTerrain.Name:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Name))
                    print("\tplotTerrain.Index:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Index))
                    print("\tplotTerrain.Water:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Water))
                    print("\tplotTerrain.ShallowWater:\t"..tostring(GameInfo.Terrains[plotTerrain].ShallowWater))
                    print("=================")
                else
                    print("======= 3 =======")
                    print("\tplot_Three = nil")
                    print("=================")
                end
                if (plot_Four ~= nil) then
                    print("======= 4 =======")
                    plotTerrain = plot_Two:GetTerrainType()
                    plot_X = plot_Four:GetX()
                    plot_Y = plot_Four:GetY()
                    print("\tMapPlot X:\t\t\t\t\t" .. tostring(plot_X))
                    print("\tMapPlot Y:\t\t\t\t\t" .. tostring(plot_Y))
                    print("\tplotTerrain.Name:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Name))
                    print("\tplotTerrain.Index:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Index))
                    print("\tplotTerrain.Water:\t\t\t"..tostring(GameInfo.Terrains[plotTerrain].Water))
                    print("\tplotTerrain.ShallowWater:\t"..tostring(GameInfo.Terrains[plotTerrain].ShallowWater))
                    print("=================")
                else
                    print("======= 4 =======")
                    print("\tplot_Four = nil")
                    print("=================")
                end
            else
                --print("Other Unit Found:\t"..unitTypeName)
            end
        end
    end
end
Events.PlayerTurnDeactivated.Add(BackwardsParameters)
 
Try Map.GetPlot instead of Map:Getplot

GetPlotXY is used with five parameters I think to get a plot at a specific distance of another, knowing the delta X and delta Y.
 
I tried GetPlot as well and it seemed even more broken.

examplePlot = GetPlot(10, 10) would grab Plot(0, 10) and usually nils due to maps being wider than their height.
Doing examplePlot:GetX() when it doesn't nil always displays 0 and examplePlot:GetY() seems to work fine.
 
Map.GetPlot

Not just GetPlot or Map:GetPlot
 
Top Bottom