Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion lama.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local env = getfenv()
local fuel = {}
local facing = {}
local position = {}
local equipment = {}

--Fuel tracking
fuel.load = function() --loading fuel data
Expand Down Expand Up @@ -84,6 +85,21 @@ facing.load = function() --loads facing / current movement direction
end
end

--equipment tracking
equipment.save = function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because you haven't defined a table as equipment. Do that instead of left/right

local file = fs.open(".lama/equipment","w")
file.write(textutils.serialize({equipment.left,equipment.right})
end

equipment.load = function()
if fs.exists(".lama/equipment") then
local file = fs.open(".lama/equipment", "r")
equipment.left, equipment.right = unpack(textutils.unserialize(file.readAll()))
else
equipment = {left={},right={}} --assume nothing
end
end

--position tracking
position.save = function() --saves position (x, y, z)
position.update() --update the position based on direction and fuel level, then save it to a file
Expand Down Expand Up @@ -198,6 +214,24 @@ env.refuel = function( n ) --needed because we depend on fuel level
return false --otherwise, return false
end

env.equipLeft = function()
local tData = turtle.getItemDetail()
local bOk = turtle.equipLeft()
if bOk then
equipment.left = tData
equipment.save
end
end

env.equipRight = function()
local tData = turtle.getItemDetail()
local bOk = turtle.equipRight()
if bOk then
equipment.right = tData
equipment.save
end
end

env.overwrite = function( t ) --writes env values into the table given
t = t or _G.turtle --or, if no value was given, _G.turtle
for k, v in pairs( env ) do
Expand Down Expand Up @@ -231,4 +265,4 @@ fuel.load()

fuel.save()
position.save()
facing.save()
facing.save()