This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Touch Buttons
Started by tysciman7, 07 June 2013 - 10:19 PMPosted 08 June 2013 - 12:19 AM
Hi i would like a way to have an elevator work with a touch screen so you can go to certain levels i have the elevator part done but i need help with the touch screen code like buttons i need three of them in the center
Posted 08 June 2013 - 02:05 AM
Look we're not your code slaves. I've give you an example of touch screen buttons, but you'll have to do everything else yourself
while true do
repeat --This wait's for you to touch the screen.
event, x, y = os.pullEvent()
until event == 'touch_screen'
if x == 1 and y == 1 then --This is the actual button... the screen is like a graph, though 1,1 is the top left part of the screen and there is no negetives..
--Do stuff
end
end
Posted 08 June 2013 - 06:03 AM
What event is touch_screen? o.O
Posted 08 June 2013 - 07:30 AM
Well, first of all, you do not have your parameters right, and just use the filter from os.pullEvent():
while true do
local event, side, x, y = os.pullEvent("monitor_touch")
--Button handling
end
Posted 08 June 2013 - 09:13 PM
Look we're not your code slaves. I've give you an example of touch screen buttons, but you'll have to do everything else yourselfwhile true do repeat --This waits for you to touch the screen. event, x, y = os.pullEvent() until event == 'touch_screen' if x == 1 and y == 1 then --This is the actual button... the screen is like a graph, though 1,1 is the top left part of the screen and there is no negetives.. --Do stuff end end
Whoa ho ho… Calm down bud. If you're not willing to help him the correct way, don't post anything. Someone with valid help will come along eventually. I see too much of that in this forum and it's quite sad.
To the original poster: http://pastebin.com/7f8y6GCZ
Take a look at that, I explain pretty much everything with –comments
I suggest learning how to use functions (If you don't already know how) and then you can use edit that code to do what you want. Hope it helps some.
Posted 08 June 2013 - 09:30 PM
Isn't the event type 'touch_screen' not 'monitor_touch'? I swore it was, anyways both works, though I noticed my way works better for the type of programs I usually make.Well, first of all, you do not have your parameters right, and just use the filter from os.pullEvent():while true do local event, side, x, y = os.pullEvent("monitor_touch") --Button handling end
Posted 08 June 2013 - 10:16 PM
Isn't the event type 'touch_screen' not 'monitor_touch'? I swore it was, anyways both works, though I noticed my way works better for the type of programs I usually make.
No, touch_screen doesnt exist. Get your facts right, because 'touch_screen' doesnt work..
Posted 08 June 2013 - 10:30 PM
Also using a loop to pull the specific event over using the filter is just pointless, and inefficient.Isn't the event type 'touch_screen' not 'monitor_touch'? I swore it was, anyways both works, though I noticed my way works better for the type of programs I usually make.
Posted 09 June 2013 - 01:04 AM
It's not pointless, for this yes, but if you want to lets say have a button only be activated by touching the monitor while having buttons on screen, then my way would work better.Also using a loop to pull the specific event over using the filter is just pointless, and inefficient.Isn't the event type 'touch_screen' not 'monitor_touch'? I swore it was, anyways both works, though I noticed my way works better for the type of programs I usually make.
Holy crap, I didn't say anything offensive in my reply, if you do not know when you use 'Get your facts right' in English it's considered rude. (Not being rude, just I know from what others say English isn't your first language), Ontopic, my bad, I knew the event, though I forgot it, next time I will confirm with the Wiki that the event type I use is correct.Isn't the event type 'touch_screen' not 'monitor_touch'? I swore it was, anyways both works, though I noticed my way works better for the type of programs I usually make.
No, touch_screen doesnt exist. Get your facts right, because 'touch_screen' doesnt work..
Posted 09 June 2013 - 02:00 AM
Not being rude, just I know from what others say English isn't your first language
I forgot it, next time I will confirm with the Wiki that the event type I use is correct.
I want to make this point: Test before you give an answer!
This might be considered rude, but I dont really care about that right now. Because testing should be the #1 thing to do on those forums (in my opinion), but I admit: I do not always test it if Im not certain. But that is not often..
Also, back on topic, if you want to catch both 'monitor_touch' and 'mouse_click',
You should use this:
while true do
local event = {os.pullEvent()} -- You could write out params, I dont do that
if event[1] == "mouse_click" then
-- stuff
elseif event[1] == "monitor_touch" then
-- stuff
end
end