19 posts
Posted 04 March 2014 - 06:42 PM
Hello there. I've been wondering around how to make a computer with advanced monitor attached to its TOP to respond on a touchschreen click on a specific location. I've made a script which prints a red-outlined button on a white background ( on a 2 by 2 grid of advanced monitors ) with the text "Touch Me!" and when the button is pressed, it gets an orange background (only in the place where there is text) The problem is where i have the if statement ( look in the program ), because it kinda ignores all the y axis of the touch. Aka i touch anywhere below the text and it still thinks the button is pressed. Any suggestions of improving the script, so the if statement thinks the button is pressed then the x axis is anywhere between 1 and 9 and the y is 1? Thanks for the time you spend reading my propably stupid question…
Link to the script:
http://pastebin.com/G4chDusTLink to anything else:
https://www.google.com/I am running an OLD version of computercraft (Minecraft 1.4.7) With Feed The Beast Ultimate modpack if that is in any attention
1281 posts
Posted 04 March 2014 - 08:44 PM
Yeah, using a bunch of or statements is a pretty inefficent and redundant way of doing it. Using greater than and less than makes it much easier.
while true do
event, side, xPos, yPos = os.pullEvent("monitor_touch")
if yPos==1
and xPos >= 1 and xPos <= 9 then
press()
unpress()
end
end
Though if you really wish to use and in combination with or, you'd add parenthese like this.
while true do
event, side, xPos, yPos = os.pullEvent("monitor_touch")
if yPos==1 and (xPos==1 or xPos==2 or xPos==3 or xPos==4 or xPos==5 or xPos==6 or xPos==7 or xPos==8 or xPos==9) then
press()
unpress()
end
end
Edited on 04 March 2014 - 07:44 PM
227 posts
Location
Germany
Posted 04 March 2014 - 08:47 PM
As you can see here:
http://www.lua.org/m...nual.html#2.5.6 and has a higher precedence than an or.
So you actually have to make brackets in your if-statement. Should look like this:
if yPos==1 and (xPos==1 or xPos==2 or xPos==3 or xPos==4 or xPos==5 or xPos==6 or xPos==7 or xPos==8 or xPos==9) then
Also it'd be easier to do the following:
if yPos == 1 and xPos >= 1 and xPos <= 9 then
Edited on 04 March 2014 - 07:48 PM
19 posts
Posted 05 March 2014 - 08:17 AM
As you can see here:
http://www.lua.org/m...nual.html#2.5.6 and has a higher precedence than an or.
So you actually have to make brackets in your if-statement. Should look like this:
if yPos==1 and (xPos==1 or xPos==2 or xPos==3 or xPos==4 or xPos==5 or xPos==6 or xPos==7 or xPos==8 or xPos==9) then
Also it'd be easier to do the following:
if yPos == 1 and xPos >= 1 and xPos <= 9 then
thanks man! Helped ALOT for my touchschreen experience!
Yeah, using a bunch of or statements is a pretty inefficent and redundant way of doing it. Using greater than and less than makes it much easier.
while true do
event, side, xPos, yPos = os.pullEvent("monitor_touch")
if yPos==1
and xPos >= 1 and xPos <= 9 then
press()
unpress()
end
end
Though if you really wish to use and in combination with or, you'd add parenthese like this.
while true do
event, side, xPos, yPos = os.pullEvent("monitor_touch")
if yPos==1 and (xPos==1 or xPos==2 or xPos==3 or xPos==4 or xPos==5 or xPos==6 or xPos==7 or xPos==8 or xPos==9) then
press()
unpress()
end
end
Thanks very much! I dodnt know that. I tried to do like i=1,9 adn if xPos==i, but that didnt work as expected.