Sorry about the unclear post - I tried to include everything needed

. Here's all the relevant code (as far as I can tell) including the functions that are called:
This function is where the error originates (GetCancelBuildID near the top calls the function where the error occurs):
Code: Select all
function AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions)
local team = teams[unitTeam]
if (team == nil) then
return false
end
if ((cmdID < 0) and (unitID == team.comm)) then
local cancelID = GetCancelBuildID(unitTeam, -cmdID, cmdParams)
if (cancelID == nil) then
AddBuild(team, -cmdID, cmdParams)
else
if (cancelID ~= team.comm) then
RemoveBuild(team, cancelID)
end
end
elseif (cmdID == CMD_DEPLOY_DELETE) then
for _,team in pairs(teams) do
if (unitID == team.comm) then
return false
end
end
RemoveBuild(team, unitID)
elseif ((#cmdParams == 1) and (cmdOptions.right) and (cmdOptions.alt)) then
for _,team in pairs(teams) do
if (unitID == team.comm) then
RemoveBuild(team, cmdParams[1])
end
end
elseif (cmdID == CMD_DEPLOY_READY) then
ReadyCommand(team, cmdOptions)
else
return true
end
return false
end
Here's GetCancelBuildID:
Code: Select all
local function GetCancelBuildID(teamID, buildID, cmdParams)
if (#cmdParams < 3) then
return nil
end
local bud = UnitDefs[buildID]
if (not bud) then
return nil
end
local bx, by, bz = cmdParams[1], cmdParams[2], cmdParams[3]
local bfacing = (#cmdParams >= 4) and cmdParams[4] or 0
local btwist = ((bfacing % 2) == 1)
local bsx = btwist and bud.ysize or bud.xsize
local bsz = btwist and bud.xsize or bud.ysize
local function max(a, b) return (a > b) and a or b end
local ss = Game.squareSize
local units = Spring.GetTeamUnits(teamID)
for _,uid in ipairs(units) do
local udid = Spring.GetUnitDefID(uid)
local ud = UnitDefs[udid]
local facing = Spring.GetUnitBuildFacing(uid)
local twist = ((facing % 2) == 1)
local sx = twist and ud.ysize or ud.xsize
local sz = twist and ud.xsize or ud.ysize
local x, y, z = Spring.GetUnitBasePosition(uid)
if (((math.abs(bx - x) * 2) <= (ss * max(sx, bsx))) and
((math.abs(bz - z) * 2) <= (ss * max(sz, bsz)))) then
return uid
end
end
return nil
end
The line:
Code: Select all
local function max(a, b) return (a > b) and a or b end
is the comparison that's causing the problem and it's when the values sx and bsx, or sz and bsz from here are both nil:
Code: Select all
if (((math.abs(bx - x) * 2) <= (ss * max(sx, bsx))) and
((math.abs(bz - z) * 2) <= (ss * max(sz, bsz)))) then
return uid
end
So basically the problem is when these equations become nil:
Code: Select all
local btwist = ((bfacing % 2) == 1)
local bsx = btwist and bud.ysize or bud.xsize
local bsz = btwist and bud.xsize or bud.ysize
...
local twist = ((facing % 2) == 1)
local sx = twist and ud.ysize or ud.xsize
local sz = twist and ud.xsize or ud.ysize
I'm only in first year programming in uni, have never really worked with coding for spring, or the lua language at all - so I'm not 100% positive on what's going on, but it seems to me that it has to do with the size and orientation of the building or placement of the cursor

.
Anyway I hope that's a bit more helpful - lemme know if there's anything else I can post :).