Jump to content




Mouse click event, changes 2 settings instead of 1.


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

#1 Dustmuz

  • Members
  • 174 posts
  • LocationDenmark

Posted 27 November 2015 - 04:38 PM

First off: The Code

the code does NOT give off an error, it works as it is now, the problem is the coding in some way

This program is written for a advanced pocket computer (wireless)
the problem lies at the mouse click event..

i have 3 locations im watching (so to speak)
X10 or 11 and Y2
X7 or 8 and Y3
X10 or 11 and Y8

whenever i click
X10 or X11 and Y2
OR
X10 or X11 and Y8

it triggers both of them, and not just one of them.. tried changing a few things.. but that didnt work out for me
would i be better off splitting them into 2 seperate funtions?? with 2 os.pullEvents

#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 27 November 2015 - 05:00 PM

Don't use multiple ifs. Use if elseif. It checks if the first condition is true. If it is, it executes the code and goes to the end. Else, it goes tot eh next elseif and checks if it is true.

#3 valithor

  • Members
  • 1,053 posts

Posted 27 November 2015 - 06:17 PM

The problem is how the program is actually reading it.

The computer reads:
X==10 or X==11 and Y==2

As if X == 10, or if X == 11 and Y == 2. So if X == 10 then it will be true and the if statement will run, without even checking the Y value.

The easiest fix would just to put parenthesis around the or statement like:
(X==10 or X==11) and Y==2

Although that would work, most people do buttons a little different:
if MouseX >=10 and MouseX<=11 and MouseY==2 then
  --# it was pressed
end

This just lets you make buttons that are bigger without having to manually put in every value (you would just have to increase the range).

edit:

Cleaned it up a little to make it easier to read.

Edited by valithor, 27 November 2015 - 10:53 PM.


#4 Dustmuz

  • Members
  • 174 posts
  • LocationDenmark

Posted 28 November 2015 - 09:36 AM

Creator and Valithor..

Thanks for your inputs..
it worked out for me using the >= <=
will be rewriting the ifs to elseifs (luckily thats easy) :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users