Advertisement
Lanzr

span_controller

Sep 15th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local controller = peripheral.wrap("right")
  2. local g_level = controller.getTargetSpeed()
  3. local statelist = {
  4.     ["top"] = redstone.getInput("top"),
  5.     ["left"] = redstone.getInput("left"),
  6. }
  7. local function init()
  8.    
  9. end
  10.  
  11. local function set_speed(pLevel)
  12.     g_level = g_level + pLevel
  13.     if g_level > 256 then
  14.         g_level =256
  15.     elseif g_level < -256 then
  16.         g_level = -256
  17.     end
  18.     -- print(g_level)
  19.     controller.setTargetSpeed(g_level)
  20. end
  21.  
  22. local function redstoneCheck()
  23.     while true do
  24.         os.pullEvent("redstone")
  25.         for side, state in pairs(statelist) do                          
  26.             if redstone.getInput(side) ~= false then
  27.                 if side == "top" then
  28.                     set_speed(4)
  29.                 elseif side == "left" then
  30.                     set_speed(-4)
  31.                 end
  32.                 break
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. -- parallel.waitForAny(redstoneCheck)
  39. redstoneCheck()
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement