Skip to content

Instantly share code, notes, and snippets.

@InternetUnexplorer
Created March 19, 2021 05:43
Show Gist options
  • Save InternetUnexplorer/7f2e47ac6984e4d4e8b052c612272d8c to your computer and use it in GitHub Desktop.
Save InternetUnexplorer/7f2e47ac6984e4d4e8b052c612272d8c to your computer and use it in GitHub Desktop.
ComputerCraft program to make setting up a GPS cluster a bit easier
local read_position
read_position = function()
local read_axis
read_axis = function(name, color)
term.setTextColor(color)
write(tostring(name) .. ": ")
term.setTextColor(colors.white)
return tonumber(read())
end
print("Enter the position of this computer (NOT the position of the modem).")
print()
local colors = {
{
"X",
colors.red
},
{
"Y",
colors.lime
},
{
"Z",
colors.lightBlue
}
}
local values = { }
for _index_0 = 1, #colors do
local _des_0 = colors[_index_0]
local name, color
name, color = _des_0[1], _des_0[2]
local value = read_axis(name, color)
if not value then
return
end
table.insert(values, value)
end
return vector.new(table.unpack(values))
end
local write_startup
write_startup = function(position)
local handle = fs.open("startup.lua", "w")
local x, y, z = position.x, position.y, position.z
handle.write("term.clear()\n" .. "term.setCursorPos(1, 1)\n" .. "shell.run(\"gps\", \"host\", " .. tostring(x) .. ", " .. tostring(y) .. ", " .. tostring(z) .. ")")
return handle.close()
end
term.clear()
term.setCursorPos(1, 1)
local position = read_position()
if position then
write_startup(position)
print()
print("Startup file written, press any key to reboot.")
os.pullEvent("key")
return os.reboot()
end
read_position = ->
read_axis = (name, color) ->
term.setTextColor color
write "#{name}: "
term.setTextColor colors.white
return tonumber read!
print "Enter the position of this computer (NOT the position of the modem)."
print!
colors = { {"X", colors.red}, {"Y", colors.lime}, {"Z", colors.lightBlue} }
values = {}
for {name, color} in *colors
value = read_axis name, color
if not value then return
table.insert values, value
vector.new table.unpack values
write_startup = (position) ->
handle = fs.open "startup.lua", "w"
x, y, z = position.x, position.y, position.z
handle.write "term.clear()\n" ..
"term.setCursorPos(1, 1)\n" ..
"shell.run(\"gps\", \"host\", #{x}, #{y}, #{z})"
handle.close!
term.clear!
term.setCursorPos 1, 1
position = read_position!
if position
write_startup position
print!
print "Startup file written, press any key to reboot."
os.pullEvent "key"
os.reboot!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment