This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tytrie's profile picture

Simple On Off Switch Touch Screen Monitor Computer Craft

Started by tytrie, 27 June 2015 - 02:02 PM
tytrie #1
Posted 27 June 2015 - 04:02 PM
So, I'm building a spawner room with different spawners right?
Well what I need help with is having buttons that when I click them they turn on or off the auto-spawners, and I have no idea how to do that. I have it so I can click the spawner and it outputs a signal to the correct spawner, but thats it.
It would be wonderful if anyone could help me.

EDIT:I am using Direwolf20's button API
My code current code is:

os.loadAPI("button")
os.loadAPI("bundle")
m = peripheral.wrap("top")
m.clear()

function fillTable()
   button.setTable("WitherS", wither, 10,20,3,5)
   button.setTable("Enderman", ender, 22,32,3,5)
   button.setTable("Blaze", blaze, 10,20,8,10)
   button.setTable("Pig", pig, 22,32,8,10)
   button.screen()
end

function getClick()
   event,side,x,y = os.pullEvent("monitor_touch")
   button.checkxy(x,y)
end

function wither()
   button.toggleButton("WitherS")
   rs.setBundledOutput('back', colors.white)
   print("WitherS")
end

function ender()
   button.toggleButton("Enderman")
   rs.setBundledOutput('back', colors.purple)
   print("Enderman")
end

function blaze()
   button.toggleButton("Blaze")
   rs.setBundledOutput('back', colors.red)
   print("Blaze")
end

function pig()
   button.toggleButton("Pig")
   rs.setBundledOutput('back', colors.pink)
   print("Pig")
end

fillTable()
button.heading("Spawners on/off")

while true do
   getClick()
end
Edited on 28 June 2015 - 11:50 PM
jerimo #2
Posted 28 June 2015 - 01:06 AM
What you need to do in simple terms is
Check for buttons clicks
Then toggle the use of the soawners, since you didnt specify much other than the situation you are faced with can't help much with specific code.
Then loop again til the next button click

To toggle a value its quite simple
toggleVar = true
if buttonClick() then
 togglevar = not togglevar
End[\code]

If you need additional help I'll be glad to help out once you've given it a try, so do attempt it and I'll check back in later today.
Good luck!
KingofGamesYami #3
Posted 28 June 2015 - 01:30 AM
It'd help a lot if we knew which button API, if any, you are using. Also, post what code you have so far, so we know how you're trying to go about doing this.
tytrie #4
Posted 29 June 2015 - 01:50 AM
It'd help a lot if we knew which button API, if any, you are using. Also, post what code you have so far, so we know how you're trying to go about doing this.

Updated the post.

What you need to do in simple terms is
Check for buttons clicks
Then toggle the use of the soawners, since you didnt specify much other than the situation you are faced with can't help much with specific code.
Then loop again til the next button click

To toggle a value its quite simple
toggleVar = true
if buttonClick() then
togglevar = not togglevar
End[\code]

If you need additional help I'll be glad to help out once you've given it a try, so do attempt it and I'll check back in later today.
Good luck!

Updated the post.