From 4becebd79f8046f55e842296757369adeb728773 Mon Sep 17 00:00:00 2001 From: HDeffo Date: Tue, 9 Feb 2016 01:44:55 -0500 Subject: [PATCH 1/2] Added equipment tracking itll be very helpful if turtles can remember what they have equipped. Sorry if i didn't write this well enough according to how you have LAMA written I only briefly read through in order to add these --- lama.lua | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lama.lua b/lama.lua index 31e7875..f378ad4 100644 --- a/lama.lua +++ b/lama.lua @@ -21,6 +21,8 @@ local env = getfenv() local fuel = {} local facing = {} local position = {} +local leftEquipment = {} +local rightEquipment = {} --Fuel tracking fuel.load = function() --loading fuel data @@ -84,6 +86,20 @@ facing.load = function() --loads facing / current movement direction end end +equipment.save = function() + local file = fs.open(".lama/equipment","w") + file.write(textutils.serialize({leftEquipment, rightEquipment}) +end + +equipment.load = function() + if fs.exists(".lama/equipment") then + local file = fs.open(".lama/equipment", "r") + equipmentLeft,equipmentRight = unpack(textutils.unserialize(file.readAll())) + else + equipmentLeft,equipmentRight = {},{} + 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 @@ -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 + equipmentLeft = tData + equipment.save + end +end + +env.equipRight = function() + local tData = turtle.getItemDetail() + local bOk = turtle.equipRight() + if bOk then + equipmentRight = 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 @@ -231,4 +265,4 @@ fuel.load() fuel.save() position.save() -facing.save() \ No newline at end of file +facing.save() From c24abdb7c05441441a4908d5ddf3a76a38640088 Mon Sep 17 00:00:00 2001 From: HDeffo Date: Tue, 9 Feb 2016 21:53:37 -0500 Subject: [PATCH 2/2] corrected the table thats what you get for programming at 3 in the morning ._. --- lama.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lama.lua b/lama.lua index f378ad4..0f55c5c 100644 --- a/lama.lua +++ b/lama.lua @@ -21,8 +21,7 @@ local env = getfenv() local fuel = {} local facing = {} local position = {} -local leftEquipment = {} -local rightEquipment = {} +local equipment = {} --Fuel tracking fuel.load = function() --loading fuel data @@ -86,17 +85,18 @@ facing.load = function() --loads facing / current movement direction end end +--equipment tracking equipment.save = function() local file = fs.open(".lama/equipment","w") - file.write(textutils.serialize({leftEquipment, rightEquipment}) + 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") - equipmentLeft,equipmentRight = unpack(textutils.unserialize(file.readAll())) + equipment.left, equipment.right = unpack(textutils.unserialize(file.readAll())) else - equipmentLeft,equipmentRight = {},{} + equipment = {left={},right={}} --assume nothing end end @@ -218,7 +218,7 @@ env.equipLeft = function() local tData = turtle.getItemDetail() local bOk = turtle.equipLeft() if bOk then - equipmentLeft = tData + equipment.left = tData equipment.save end end @@ -227,7 +227,7 @@ env.equipRight = function() local tData = turtle.getItemDetail() local bOk = turtle.equipRight() if bOk then - equipmentRight = tData + equipment.right = tData equipment.save end end