Jump to content




(mouse click) #Detects when the x is between 1-5 and y is equal to 1


8 replies to this topic

#1 LabyStudio

  • Members
  • 39 posts

Posted 15 July 2013 - 09:20 AM

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



#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 15 July 2013 - 10:09 AM

You should use tables if you need to detect when random coordinates are clicked:

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 LabyStudio

  • Members
  • 39 posts

Posted 15 July 2013 - 10:20 AM

thank you

#4 LabyStudio

  • Members
  • 39 posts

Posted 15 July 2013 - 10:48 AM

View PostBubba, on 15 July 2013 - 10:09 AM, said:

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

'then' expected! :/

#5 lieudusty

  • Members
  • 419 posts

Posted 15 July 2013 - 10:51 AM

I think your comparison signs are mixed up. Try switching them around: >= to <=

#6 LabyStudio

  • Members
  • 39 posts

Posted 15 July 2013 - 10:56 AM

View Postlieudusty, 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 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

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 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 15 July 2013 - 11:10 AM

And please use the [code] tags

#9 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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