68 lines
No EOL
1.5 KiB
Lua
68 lines
No EOL
1.5 KiB
Lua
local modules = {}
|
|
|
|
local function getIndex(tab, val)
|
|
local index = nil
|
|
for i, v in ipairs (tab) do
|
|
if (v == val) then
|
|
index = i
|
|
end
|
|
end
|
|
return index
|
|
end
|
|
|
|
|
|
local kinetic = peripheral.wrap("back")
|
|
local canvas = peripheral.wrap("back").canvas()
|
|
|
|
timer = os.startTimer(0.5)
|
|
canvas.clear()
|
|
|
|
local group = canvas.addGroup({ 0, 0 })
|
|
local text = group.addText({ 5, 5 }, "")
|
|
|
|
text.setText("this is NOT a client")
|
|
|
|
local moduleText = group.addText({ 5, 15 }, table.concat(modules, "\n"))
|
|
moduleText.setScale(0.5)
|
|
local function enableModule(module)
|
|
table.insert(modules, module)
|
|
moduleText.setText(table.concat(modules, "\n"))
|
|
end
|
|
|
|
local function disableModule(module)
|
|
local idx = getIndex(modules, module)
|
|
table.remove(modules, idx)
|
|
moduleText.setText(table.concat(modules, "\n"))
|
|
end
|
|
|
|
local function isModuleEnabled(module)
|
|
local idx = getIndex(modules, module)
|
|
return idx ~= nil
|
|
end
|
|
|
|
function checkKey()
|
|
while true do
|
|
local event, key, is_held = os.pullEvent("key")
|
|
if keys.getName(key) == "g" then
|
|
if isModuleEnabled("flight") then
|
|
disableModule("flight")
|
|
else
|
|
enableModule("flight")
|
|
timer = os.startTimer(0.5)
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
function flyEvent()
|
|
while true do
|
|
local _, tid = os.pullEvent("timer")
|
|
if tid == timer and isModuleEnabled("flight") then
|
|
timer = os.startTimer(0.5)
|
|
kinetic.launch(0, -90, 4);
|
|
end
|
|
end
|
|
end
|
|
|
|
parallel.waitForAll(checkKey, flyEvent) |