local event, btn, mousex, mouseY = os.pullEvent("mouse_click") If mouseX>=1 and mouseX=<5 and mouseY==1 then --#Detects when the x is between 1-5 and y is equal to 1 print("test") end
1
(mouse click) #Detects when the x is between 1-5 and y is equal to 1
Started by LabyStudio, Jul 15 2013 09:20 AM
8 replies to this topic
#1
Posted 15 July 2013 - 09:20 AM
#2
Posted 15 July 2013 - 10:09 AM
You should use tables if you need to detect when random coordinates are clicked:
If you need coordinates that are in a range, use a simple if statement:
local coords = { 1,2,1,3,1,4,1,5,1,6 } local event, btn, mouseX, mouseY = os.pullEvent("mouse_click") for index=1, #coords, 2 do --#This will increment by two if mouseX == coords[index] and mouseY==coords[index+1] then print("test") end end
If you need coordinates that are in a range, use a simple if statement:
local event, btn, mousex, mouseY = os.pullEvent("mouse_click") if mouseX>=1 and mouseX=<5 and mouseY==1 then --#Detects when the x is between 1-5 and y is equal to 1 print("test") end
#3
Posted 15 July 2013 - 10:20 AM
thank you
#5
Posted 15 July 2013 - 10:51 AM
I think your comparison signs are mixed up. Try switching them around: >= to <=
#6
Posted 15 July 2013 - 10:56 AM
lieudusty, on 15 July 2013 - 10:51 AM, said:
I think your comparison signs are mixed up. Try switching them around: >= to <=
local event, btn, mousex, mouseY = os.pullEvent("mouse_click") if mouseX<=1 and mouseX<=5 and mouseY==1 then -- [ <= ] print("test") end
attempt to compare __le on nil an number :/
and:
local event, btn, mousex, mouseY = os.pullEvent("mouse_click") if mouseX<=1 and mouseX=<5 and mouseY==1 then -- [ =< ] print("test") end
'then' expected! :/
#7
Posted 15 July 2013 - 11:05 AM
Please look thoroughly in your code before pasting it here again.
local event, btn, mouseX, mouseY = os.pullEvent("mouse_click") --# the first "mouseX" here wasn't capitalized. if mouseX >= 1 and mouseX <= 5 and mouseY == 1 then --# also, the first symbol should be >= print("test") end
#8
Posted 15 July 2013 - 11:10 AM
And please use the [code] tags
#9
Posted 15 July 2013 - 12:12 PM
Do not remove your title or question post. Please put them back so that your question will be findable in the search again.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users