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

creating buttons on touchscreen

Started by iRiky, 13 April 2013 - 06:48 AM
iRiky #1
Posted 13 April 2013 - 08:48 AM
hi i need to create some touchscreen buttons for a program but it seems to me too hard
i'm using the Direwolf20's Button API but i've still problems
This is the code i wrote so far:

os.loadAPI("button")
mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()

function title()
m.setCursorPos(15,1)
m.write(" Teleporting System ")
end
function workshop()
print("hello world")
end
function fillTable()
button.setTable("workshop",workshop,2,3,10,6)
end
--main program
title()
fillTable()

and there's the link for the pastebin of Direwolf20's button API


http://pastebin.com/1iwuzsh8

can you figure out why in my 5*4 monitor i can't see the button ?
Please help me !
SuicidalSTDz #2
Posted 13 April 2013 - 09:12 AM
hi i need to create some touchscreen buttons for a program but it seems to me too hard
i'm using the Direwolf20's Button API but i've still problems
This is the code i wrote so far:

os.loadAPI("button")
mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()

function title()
m.setCursorPos(15,1)
m.write(" Teleporting System ")
end
function workshop()
print("hello world")
end
function fillTable()
button.setTable("workshop",workshop,2,3,10,6)
end
--main program
title()
fillTable()

and there's the link for the pastebin of Direwolf20's button API


http://pastebin.com/1iwuzsh8

can you figure out why in my 5*4 monitor i can't see the button ?
Please help me !
mon = peripheral.wrap("top")

m.clear()
m.setCursorPos(15,1)
m.write()

You are not calling the peripheral.

Just use this:

term.redirect(peripheral.wrap("top"))

This will allow you to use term.clear() and such while using the monitor.
iRiky #3
Posted 13 April 2013 - 09:35 AM
why if i do

m = peripheral.wrap("top")

?
SuicidalSTDz #4
Posted 13 April 2013 - 09:52 AM
why if i do

m = peripheral.wrap("top")

?
That will work. You just have to remember to call it accordingly, for example m.clear()
iRiky #5
Posted 13 April 2013 - 10:11 AM
ok thanks but it still doesn't work :(/>
any others suggestions ?
0wns2Build #6
Posted 23 May 2013 - 02:44 AM
you use the api on the wrong way you should use a code like this.

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

function fillTable()
		button.setTable("Peat",peat,3,17,1,3)
		button.setTable("Pumpkin",pumpkin,3,17,5,7)
		button.setTable("Melon",melon,3,17,9,11)
		button.setTable("Netherwart",netherwart,3,17,13,15)
		button.setTable("Wheat 1",wheat1,3,17,17,19)
		button.setTable("Wheat 2",wheat2,23,37,1,3)
		button.setTable("Oak",oak,23,37,5,7)
		button.setTable("Birch",birch,23,37,9,11)
		button.setTable("Spruce",spruce,23,37,13,15)
		button.setTable("Jungle",jungle,23,37,17,19)
		button.screen()
end

function getClick()
		event,side,x,y = os.pullEvent("monitor_touch")
		button.checkxy(x, y)
end			 																																																						
function pulse()
		redstone.setOutput("back", true)
		sleep(0,5)
		redstone.setOutput("back", false)
end

function peat()
		button.toggleButton("Peat")
		p.setFreq(151)
		pulse()
end

function pumpkin()
		button.toggleButton("Pumpkin")
		p.setFreq(152)
		pulse()
end

function melon()
		button.toggleButton("Melon")
		p.setFreq(153)
		pulse()
end

function netherwart()
		button.toggleButton("Netherwart")
		p.setFreq(154)
		pulse()
end

function wheat1()
		button.toggleButton("Wheat 1")
		p.setFreq(155)
		pulse()
end

function wheat2()
		button.toggleButton("Wheat 2")
		p.setFreq(156)
		pulse()
end

function oak()
		button.toggleButton("Oak")
		p.setFreq(157)
		pulse()
end

function birch()
		button.toggleButton("Birch")
		p.setFreq(158)
		pulse()
end

function spruce()
		button.toggleButton("Spruce")
		p.setFreq(159)
		pulse()
end

function jungle()
		button.toggleButton("Jungle")
		p.setFreq(160)
		pulse()
end

fillTable()
while true do getClick() end
this is a link to the pastebin code http://pastebin.com/ug7DQbaF and if you use the code "button.heading("yourtext") you can have a text above the buttons
Zudo #7
Posted 23 May 2013 - 02:50 AM
Whats with the line numbers in the wrong place?
0wns2Build #8
Posted 23 May 2013 - 05:22 AM
i felt so free to take your code and edit it in such a way it will work with the api here it is:

os.loadAPI("button")
m = peripheral.wrap("top")
rednet.open("bottom")
m.clear()
function fillTable()
  button.setTable("Workshop",workshop,2,3,10,6)
  button.screen()
end
function pulse()
  redstone.setOutput("back", true)
  sleep(0,5)
  redstone.setOutput("back", false)
function getClick()
  event,side,x,y = pullEvent("monitor_touch")
  button.checkxy(x, y)
end
function workshop()
  button.flash()
--all underneath this you can edit the fuction to you own needs.
  pulse()
end
fillTable()
button.header("Teleporting System")
while true do getClick() end
the function name workshop is the action that folows by pressing the button. here's the pastebin link: http://pastebin.com/Qizcdyx3 . btw the reason you button didn't react is because the getClick function and the action of the button itself in the form of the workshop function missed and of course you do have to have "while true do getClick() end" line in the programm. but i am sure the code i provide works unless i made a typeo.
Shnupbups #9
Posted 23 May 2013 - 06:32 AM
The reason why the original code is not working, is that you have overridden the 'button' API that you loaded by making a table called button. Rename the button table. Also, if you wrap it as mon, use it as mon.
DerTroglodyt #10
Posted 13 June 2013 - 10:10 AM
Just be consistent: mon or m but not both. ;-)

mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()

Should be
mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
mon.clear()

or

m = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()
Engineer #11
Posted 13 June 2013 - 02:55 PM
Just be consistent: mon or m but not both. ;-)

mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()

Should be
mon = peripheral.wrap("top")
rednet.open("bottom")
local button={}
mon.clear()

or

m = peripheral.wrap("top")
rednet.open("bottom")
local button={}
m.clear()

It should be:

local mon = peripheral.wrap("top")
rednet.open("bottom")
--# local button = {} DONT OVERRIDE THE API!:P/>
mon.clear()