Skip to content

Instantly share code, notes, and snippets.

@metehus
Created July 2, 2022 01:53
Show Gist options
  • Save metehus/c83607d852f9fd13aa93a290ed894613 to your computer and use it in GitHub Desktop.
Save metehus/c83607d852f9fd13aa93a290ed894613 to your computer and use it in GitHub Desktop.
Elevador no computercraft
local GuiH = require('GuiH')
local hatch = colors.red
local parada = colors.pink
local andar = 0
local andarSolicitado = 0
local ignorePulse = false
local function loop()
while true do
local floorPulse = redstone.testBundledInput('left', colors.pink)
if floorPulse and not ignorePulse then
if andarSolicitado > andar then
andar = andar + 1
print('pulse: +1')
ignorePulse = true
sleep(0.5)
ignorePulse = false
end
if andar > andarSolicitado then
andar = andar - 1
print('pulse: -1')
write('andar ')
print(andar)
ignorePulse = true
sleep(0.5)
ignorePulse = false
end
end
if andar == andarSolicitado then
if andar == 0 then
redstone.setBundledOutput('back', hatch)
else
redstone.setBundledOutput('back', parada)
end
end
sleep(0.05)
end
end
local function createGui(screen)
print('Iniciando telas...')
screen.setTextScale(0.6)
local gui = GuiH.create_gui(screen)
gui.create.button({
x=3,
y=2,
width=11,
height=3,
background_color=colors.magenta,
text=gui.text({ text ='Térreo', centered = true, transparent = true }),
on_click = function (object)
print('solicitado 0')
andarSolicitado = 0
ignorePulse = true
redstone.setBundledOutput('back', colors.red)
sleep(0.7)
ignorePulse = false
end
})
gui.create.button({
x=3,
y=6,
width=11,
height=3,
background_color=colors.blue,
text=gui.text({
text = 'Laborat?rio',
centered = true,
transparent = true
}),
on_click = function (object)
print('solicitado 1')
ignorePulse = true
andarSolicitado = 1
if andar == 0 then
redstone.setBundledOutput('back', colors.combine(colors.blue, colors.red))
sleep(1)
redstone.setBundledOutput('back', colors.blue)
end
if andar > andarSolicitado then
redstone.setBundledOutput('back', 0)
end
if andarSolicitado > andar then
redstone.setBundledOutput('back', colors.blue)
end
sleep(0.5)
ignorePulse = false
end
})
gui.create.button({
x=3,
y=12,
width=11,
height=3,
background_color=colors.green,
text=gui.text({
text = 'Reator',
centered = true,
transparent = true
}),
on_click = function (object)
print('solicitado 2')
ignorePulse = true
andarSolicitado = 2
if andar == 0 then
redstone.setBundledOutput('back', colors.combine(colors.blue, colors.red))
sleep(1)
redstone.setBundledOutput('back', colors.blue)
end
if andar > andarSolicitado then
redstone.setBundledOutput('back', 0)
end
if andarSolicitado > andar then
redstone.setBundledOutput('back', colors.blue)
end
sleep(0.5)
ignorePulse = false
end
})
gui.execute(loop)
end
print('ELEvador 1.0')
mon_cima = peripheral.wrap('monitor_7')
mon_andar1 = peripheral.wrap('monitor_6')
mon_reator = peripheral.wrap('monitor_5')
mon_andar1.clear()
mon_andar1.write(':(')
parallel.waitForAll(
function()
createGui(mon_cima)
end,
function()
createGui(mon_andar1)
end,
function()
createGui(mon_reator)
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment