Need help with a touch screen controlled mob spawner

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Jayrum

New Member
Jul 29, 2019
2
0
0
I have a code for one but when I click the button on the screen it sends out a redstone signal. I need it so when I click it, it stops sending out the redstone signal. I'm using bundled cable and FTB Ultimate.
Here is the code:
  1. --Requires advanced monitors and computers!!!
  2. local rsSide = "back"
  3. local monitorSide = "right"
  4. function testForMonitor(_side)
  5. if peripheral.getType(_side) then
  6. if peripheral.getType(_side) == "monitor" then
  7. return true
  8. else return false end
  9. else return false end
  10. end
  11. Args = { ... }
  12. if #Args < 1 then
  13. print("Usage: "..fs.getName(shell.getRunningProgram()).." <monitor side> [cable side]")
  14. return
  15. elseif #Args > 1 then
  16. monitorSide = Args[1]
  17. rsSide = Args[2]
  18. if not testForMonitor(monitorSide) then
  19. print("There is no valid monitor on that side.")
  20. return
  21. end
  22. elseif #Args == 1 then
  23. monitorSide = Args[1]
  24. if not testForMonitor(monitorSide) then
  25. print("There is no valid monitor on that side.")
  26. return
  27. end
  28. else
  29. print("Error!!!")
  30. return
  31. end
  32. function toggle(n)
  33. if not n then
  34. return
  35. end
  36. local state = button[n].state
  37. if state then
  38. state = false
  39. else
  40. state = true
  41. end
  42. button[n].state = state
  43. return state
  44. end
  45. function sayState(n)
  46. if not n then
  47. return
  48. end
  49. x = button[n].x - 1
  50. y = button[n].y
  51. term.setCursorPos(x,y)
  52. if button[n].state then
  53. term.setTextColor(colors.lime)
  54. write("on ")
  55. term.setTextColor(colors.white)
  56. else
  57. term.setTextColor(colors.red)
  58. write("off")
  59. term.setTextColor(colors.white)
  60. end
  61. end
  62. function getButton(xPos,yPos)
  63. for i=1,12 do
  64. bxPos = button.x
    [*] byPos = button.y
    [*] xMax = bxPos + 2
    [*] xMin = bxPos - 2
    [*] yMax = byPos + 1
    [*] yMin = byPos - 1
    [*] if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
    [*] return i
    [*] end
    [*] end
    [*]end
    [*]
    [*]function mPrint(w)
    [*] write(w)
    [*] x,y=term.getCursorPos()
    [*] term.setCursorPos(1, y+1)
    [*]end
    [*]
    [*]function allTheSame()
    [*] local state = button[1].state
    [*] for i = 2,10 do
    [*] if state == button.state then
    [*] else return false
    [*] end
    [*] end
    [*] return true
    [*]end
    [*]
    [*]function stateWriter()
    [*] mPrint(" _____ _____ _____ _____")
    [*] write(" ")
    [*] for i = 1,4 do
    [*] write("|")
    [*] term.setTextColor(colors.red)
    [*] write("off")
    [*] term.setTextColor(colors.white)
    [*] if i<4 then
    [*] write("| ")
    [*] else
    [*] mPrint("|")
    [*] end
    [*] end
    [*] mPrint(" ~~~~~ ~~~~~ ~~~~~ ~~~~~")
    [*]end
    [*]
    [*]function mobTypeWrite(_line,_time)
    [*] term.setCursorPos(1,_line)
    [*] write(" ")
    [*] local additive = (_time - 1) * 4
    [*] local currentx = 3
    [*] for i = 1,4 do
    [*] local buttonNumber = additive + i
    [*] write(button[buttonNumber].mob)
    [*] if i == 4 then
    [*]
    [*] else
    [*] currentx = currentx + 10
    [*] term.setCursorPos(currentx,_line)
    [*] end
    [*] end
    [*] term.setCursorPos(1, _line + 1)
    [*]end
    [*]
    [*]
    [*]function startText()
    [*] term.setCursorPos(1,1)
    [*] mPrint("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    [*] mPrint(" Welcome to spawn select! Control mob")
    [*] mPrint(" spawn choice by right click on screen")
    [*] mPrint(" ")
    [*] mobTypeWrite(5,1)
    [*] stateWriter()
    [*] mPrint(" ")
    [*] mobTypeWrite(10,2)
    [*] stateWriter()
    [*] mPrint(" ")
    [*] mobTypeWrite(15,3)
    [*] stateWriter()
    [*] mPrint("_______________________________________")
    [*]end
    [*]
    [*]function bundleState()
    [*] running = 0
    [*] for light = 1, 10 do
    [*] if button[light].state == true then
    [*] running = running + button[light].color
    [*] end
    [*] end
    [*] return running
    [*]end
    [*]
    [*]function refresh()
    [*] redstone.setBundledOutput(rsSide, bundleState())
    [*]end
    [*]
    [*]display = peripheral.wrap(monitorSide)
    [*]term.redirect(display)
    [*]term.clear()
    [*]term.setCursorPos(1,1)
    [*]
    [*]--This is the table that controls everything. Don't touch unless you know what you are doing.
    [*]
    [*]button = {
    [*] [1] = {x = 5; y = 7; state = false; color = colors.white; mob = "Skele"},
    [*] [2] = {x = 15; y = 7; state = false; color = colors.orange; mob = "Wither"},
    [*] [3] = {x = 25; y = 7; state = false; color = colors.magenta; mob = "Ender"},
    [*] [4] = {x = 35; y = 7; state = false; color = colors.lightBlue; mob = "Zombie"},
    [*]
    [*] [5] = {x = 5; y = 12; state = false; color = colors.yellow; mob = "Creep"},
    [*] [6] = {x = 15; y = 12; state = false; color = colors.lime; mob = "Witch"},
    [*] [7] = {x = 25; y = 12; state = false; color = colors.pink; mob = "Pigman"},
    [*] [8] = {x = 35; y = 12; state = false; color = colors.gray; mob = "Cow"},
    [*]
    [*] [9] = {x = 5; y = 17; state = false; color = colors.lightGray; mob = "Blaze"},
    [*] [10] = {x = 15; y = 17; state = false; color = colors.cyan; mob = "Slime"},
    [*] [11] = {x = 25; y = 17; state = false; color = colors.purple; mob = "Toggle"},
    [*] [12] = {x = 35; y = 17; state = false; color = colors.blue; mob = "Master"}
    [*]
    [*]}
    [*]
    [*]local resume = true
    [*]startText()
    [*]for i = 1,10 do
    [*] sayState(i)
    [*]end
    [*]term.setCursorPos(button[12].x-1,button[12].y)
    [*]term.setTextColor(colors.red)
    [*]write("off")
    [*]term.setTextColor(colors.white)
    [*]term.setCursorPos(button[11].x-1,button[11].y)
    [*]term.setTextColor(colors.cyan)
    [*]write("TGL")
    [*]term.setTextColor(colors.white)
    [*]refresh()
    [*]while resume == true do
    [*] local event, side, xPos, yPos = os.pullEvent("monitor_touch")
    [*] local selectedButton = getButton(xPos,yPos)
    [*] if selectedButton == 11 then
    [*] for i = 1,10 do
    [*] toggle(i)
    [*] end
    [*] elseif selectedButton == 12 then
    [*] toggle(12)
    [*] for i=1,10 do
    [*] button.state = button[12].state
    [*] end
    [*] sayState(12)
    [*] allSame=true
    [*] else
    [*] term.setCursorPos(button[12].x - 1, button[12].y)
    [*] term.setTextColor(colors.lightGray)
    [*] write("---")
    [*] term.setTextColor(colors.white)
    [*] toggle(selectedButton)
    [*] end
    [*] for i=1,10 do
    [*] sayState(i)
    [*] end
    [*] if allTheSame() then
    [*] button[12].state = button[1].state
    [*] sayState(12)
    [*] else
    [*] term.setCursorPos(button[12].x - 1, button[12].y)
    [*] term.setTextColor(colors.lightGray)
    [*] write("---")
    [*] term.setTextColor(colors.white)
    [*] end
    [*] refresh()
    [*]end
    [*]
    [*]-- optional, more color appropriate colors
    [*]--[==[ button = {
    [*] [1] = {x = 5; y = 7; state = false; color = colors.lightGray; mob = "Skele"},
    [*] [2] = {x = 15; y = 7; state = false; color = colors.gray; mob = "Wither"},
    [*] [3] = {x = 25; y = 7; state = false; color = colors.purple; mob = "Ender"},
    [*] [4] = {x = 35; y = 7; state = false; color = colors.cyan; mob = "Zombie"},
    [*]
    [*] [5] = {x = 5; y = 12; state = false; color = colors.green; mob = "Creep"},
    [*] [6] = {x = 15; y = 12; state = false; color = colors.magenta; mob = "Witch"},
    [*] [7] = {x = 25; y = 12; state = false; color = colors.pink; mob = "Pigman"},
    [*] [8] = {x = 35; y = 12; state = false; color = colors.brown; mob = "Cow"},
    [*]
    [*] [9] = {x = 5; y = 17; state = false; color = colors.yellow; mob = "Blaze"},
    [*] [10] = {x = 15; y = 17; state = false; color = colors.lime; mob = "Slime"},
    [*] [11] = {x = 25; y = 17; state = false; color = colors.purple; mob = "Toggle"},
    [*] [12] = {x = 35; y = 17; state = false; color = colors.blue; mob = "Master"}
    [*]
    [*]} ]==]