Jump to content




Touch Buttons


  • You cannot reply to this topic
9 replies to this topic

#1 tysciman7

  • Members
  • 41 posts

Posted 07 June 2013 - 11:19 PM

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

#2 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 08 June 2013 - 01: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


#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 June 2013 - 05:03 AM

What event is touch_screen? o.O

#4 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 08 June 2013 - 06: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


#5 Xenthera

  • Members
  • 170 posts

Posted 08 June 2013 - 08:13 PM

 Spongy141, on 08 June 2013 - 01:05 AM, said:

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 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.

#6 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 08 June 2013 - 08:30 PM

 Engineer, on 08 June 2013 - 06:30 AM, said:

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
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.

#7 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 08 June 2013 - 09:16 PM

 Spongy141, on 08 June 2013 - 08:30 PM, said:

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..

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 08 June 2013 - 09:30 PM

 Spongy141, on 08 June 2013 - 08:30 PM, said:

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.
Also using a loop to pull the specific event over using the filter is just pointless, and inefficient.

#9 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 09 June 2013 - 12:04 AM

 theoriginalbit, on 08 June 2013 - 09:30 PM, said:

 Spongy141, on 08 June 2013 - 08:30 PM, said:

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.
Also using a loop to pull the specific event over using the filter is just pointless, and inefficient.
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.

 Engineer, on 08 June 2013 - 09:16 PM, said:

 Spongy141, on 08 June 2013 - 08:30 PM, said:

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..
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.

#10 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 09 June 2013 - 01:00 AM

 Spongy141, on 09 June 2013 - 12:04 AM, said:

Not being rude, just I know from what others say English isn't your first language


Posted Image

 Spongy141, on 09 June 2013 - 12:04 AM, said:

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users