Skip to content

Commit

Permalink
fix: pickups
Browse files Browse the repository at this point in the history
Dirty hack to get rid of the error:
Cutter.lua:1494: invalid argument #1 to 'ipairs' (table expected, got nil)
Seems like pickups aren't properly implemented for AI work.

Also included a DevHelper improvement.

#60
  • Loading branch information
Peter Vaiko committed Dec 27, 2024
1 parent 7afa211 commit 6559405
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions scripts/ai/controllers/CutterController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ CutterController = CpObject(ImplementController)
function CutterController:init(vehicle, implement)
ImplementController.init(self, vehicle, implement)
self.cutterSpec = self.implement.spec_cutter
-- To avoid the error thrown for pickups:
-- Cutter.lua:1494: invalid argument #1 to 'ipairs' (table expected, got nil)
self.cutterSpec.fruitTypeIndices = {}
end

function CutterController:getDriveData()
Expand Down
31 changes: 16 additions & 15 deletions scripts/dev/DevHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ function DevHelper:update()

end

function DevHelper:overlapBoxCallback(transformId)
function DevHelper:overlapBoxCallback(transformId, subShapeIndex)
local collidingObject = g_currentMission.nodeToObject[transformId]
local text = ''
for i = 0, getNumOfUserAttributes(transformId) - 1 do
local type, name, x = getUserAttributeByIndex(transformId, i)
text = tostring(i) .. ':' .. (type or '?') .. '/' .. (name or '?') .. '/' .. (x or '?')
local text = tostring(subShapeIndex)
for key, classId in pairs(ClassIds) do
if getHasClassId(transformId, classId) then
text = text .. ' ' .. key
end
end
for key, rigidBodyType in pairs(RigidBodyType) do
if getRigidBodyType(transformId) == rigidBodyType then
text = text .. ' ' .. key
end
end
if collidingObject then
if collidingObject.getRootVehicle then
Expand All @@ -112,14 +118,12 @@ function DevHelper:overlapBoxCallback(transformId)
text = text .. ' ' .. collidingObject.getName and collidingObject:getName() or 'N/A'
end
end
else
for key, classId in pairs(ClassIds) do
if getHasClassId(transformId, classId) then
text = text .. ' ' .. key
end
end
end
table.insert(self.data.collidingShapes, text .. ' ' .. getRigidBodyType(transformId))
for i = 0, getNumOfUserAttributes(transformId) - 1 do
local type, name, x = getUserAttributeByIndex(transformId, i)
text = text .. ' ' .. tostring(i) .. ':' .. (type or '?') .. '/' .. (name or '?') .. '/' .. (x or '?')
end
table.insert(self.data.collidingShapes, text)
end

-- Left-Alt + , (<) = mark current position as start for pathfinding
Expand Down Expand Up @@ -206,9 +210,6 @@ function DevHelper:fillDisplayData()
table.insert(displayData, {name = 'isOnFieldArea', value = self.data.isOnFieldArea})
table.insert(displayData, {name = 'onFieldArea', value = self.data.onFieldArea})
table.insert(displayData, {name = 'totalOnFieldArea', value = self.data.totalOnFieldArea})
table.insert(displayData, {name = 'nx', value = self.data.nx})
table.insert(displayData, {name = 'ny', value = self.data.ny})
table.insert(displayData, {name = 'nz', value = self.data.nz})
for i = 1, #self.data.collidingShapes do
table.insert(displayData, {name = 'collidingShapes ' .. i, value = self.data.collidingShapes[i]})
end
Expand Down

0 comments on commit 6559405

Please sign in to comment.