items = { } -- Global variable, reusable container for findGlobalObjects. Reusing this table avoids costs of -- constructing and destructing it every time we call findGlobalObjects(). Be sure to clear the -- table before reusing it! bot = nil function generateItem(num, x, y) local obj1 if num == 0 then obj1 = Asteroid.new() elseif num == 1 then obj1 = Mine.new() elseif num == 2 then obj1 = FlagItem.new() elseif num == 3 then obj1 = SpyBug.new() end obj1:setLoc(point.new(x, y)) levelgen:addItem(obj1) return obj1 end function onPlayerJoined(something, playerinfo) if bot == nil then unsubscribe(Event.PlayerJoined) bot = playerinfo:getShip() return end end function onShipEnteredZone(ship, zone, zoneType, zoneId) table.clear(items) bot:findGlobalObjects(items, ObjType.Flag) -- Returns a list of all items of type objType in the game for index, item in ipairs(items) do -- Iterate through all found items local l = item:getLoc() generateItem(3, l.x, l.y) end end function onTick(timePassed) if bot == nil then subscribe(Event.PlayerJoined) levelgen:addLevelLine("Robot") end end function main() subscribe(Event.tick) subscribe(Event.ShipEnteredZone) end