Jump to content




creating buttons on touchscreen


10 replies to this topic

#1 iRiky

  • Members
  • 24 posts

Posted 13 April 2013 - 07: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 !

#2 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 13 April 2013 - 08:12 AM

View PostiRiky, on 13 April 2013 - 07:48 AM, said:

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.

#3 iRiky

  • Members
  • 24 posts

Posted 13 April 2013 - 08:35 AM

why if i do

m = peripheral.wrap("top")

?

#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 13 April 2013 - 08:52 AM

View PostiRiky, on 13 April 2013 - 08:35 AM, said:

why if i do

m = peripheral.wrap("top")

?
That will work. You just have to remember to call it accordingly, for example m.clear()

#5 iRiky

  • Members
  • 24 posts

Posted 13 April 2013 - 09:11 AM

ok thanks but it still doesn't work :(
any others suggestions ?

#6 0wns2Build

  • New Members
  • 2 posts
  • LocationSomewhere where you are Not?!

Posted 23 May 2013 - 01: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

#7 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 23 May 2013 - 01:50 AM

Whats with the line numbers in the wrong place?

#8 0wns2Build

  • New Members
  • 2 posts
  • LocationSomewhere where you are Not?!

Posted 23 May 2013 - 04: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.

#9 Shnupbups

  • Members
  • 596 posts
  • LocationThat place over there. Y'know. The one where I am.

Posted 23 May 2013 - 05: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.

#10 DerTroglodyt

  • Members
  • 7 posts

Posted 13 June 2013 - 09: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()

#11 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 June 2013 - 01:55 PM

View PostDerTroglodyt, on 13 June 2013 - 09:10 AM, said:

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()






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users