Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Prevent events you have on MouseClick() from looping

Author
Message
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 8th Aug 2009 14:16 Edited at: 8th Aug 2009 14:18
Well, since I needed this little bit of code myself, and couldn't find a simple one that didn't have to do with a load of weird ass flags, I decided to make one myself.

What it does is really simple, if you have(for example) a graphical button(e.g. Image pasted on the screen) you don't want this event to loop when the user presses it, because this might open like 20 internet explorers because the user is running at a high framerate, and the program registered the click 20 times before the user released the button. This simple code prevents that.

First of all, add this global somewhere to your declarations.


It's set to 0 by default, just to prevent any bugs from happening before the click function is called. Now, the function itself is pretty easy, and works EXACTLY the same as If MouseClick() = 0/1, but it only registers Mouse Button 1 at this moment... So it will always output 1 or 0, any other button will return 0.

You can paste this at the end of your code, or in your Functions.dba, or whatever you call it.


Now, it's pretty easy to call this. As I said it works the same as the MouseClick() command, without the looping issues, and without support for other Mouse Buttons besides 1. Here's an example of how to use it:


The above code has been tested, and can be pasted directly into your IDE to try it yourself.

Enjoy!

It's not the world that turns against you, it's you that turns against the world.
NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 9th Aug 2009 23:12 Edited at: 9th Aug 2009 23:13
Wouldn't it be better to check mouseclick() once per loop on every sync and instead of using a function to ask for mouse status, check against a variable? You're talking loads of overhead for a stack of functions.

Oh, and indent your code. I keep expecting the function to end when in fact it doesn't.

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 10th Aug 2009 10:12
Quote: "Wouldn't it be better to check mouseclick() once per loop on every sync and instead of using a function to ask for mouse status, check against a variable? You're talking loads of overhead for a stack of functions."


Could be better yes, however I didn't think of it that way, and just made this in a few minutes I'll change that when I get the time.

Quote: "Oh, and indent your code. I keep expecting the function to end when in fact it doesn't."

I never do that in a Function, confuses the hell out of me

It's not the world that turns against you, it's you that turns against the world.
chwilly
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location:
Posted: 11th Aug 2009 06:01
Hmmmm...




This is all I do if I don't want the click to be repeatedly read. Of course this can't be used while in the game of course because it stop all processing until the mouse is released but in menus and such it's fine.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 11th Aug 2009 20:15
I just do this:

Only one flag to worry about, and it works in loops.

What about returning different values for mousehold and mouserelease? Add more features like that and it might be worth it.



Deego
15
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 12th Aug 2009 00:55
I use this for every input in my programs.



One function to check for 4 input states, and it can be modified to any input.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Oct 2009 04:24 Edited at: 31st Oct 2009 04:27
I copied this from one of Mr. Tank's programs (I think he is Dr. Tank now).


I don't own DBP so I hope I used GLOBAL correctly. Can you define them as bits? That would be ideal.
I've started making a GUI; flags like Bmac's are the obvious choice for that because you can have multiple actions.

TGC Forum - converting error messages into sarcasm since 2002.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 31st Oct 2009 04:30
OBese - That's a pretty good idea, but wouldn't right-clicks mess it up a bit?

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Oct 2009 04:39
@Bmac
If you only wanted it to work for left mouse clicks you'd do this.


Or to completely ignore other buttons


Another nice thing about this that I've just realised: because there are two variables you can also have an release condition.

I hope that works anyway...

TGC Forum - converting error messages into sarcasm since 2002.
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 5th Nov 2009 18:52 Edited at: 5th Nov 2009 18:54
Here's my version. You can set a key (unique ID) so you can get different results for each key. For example, if you are checking mouse-clicks on sprites in one function and checking mouse clicks for objects in another function. It is also self-contained - no need to initialize. The function does differentiate between different mouse-clicks, so a left-click and then a simultaneous right-click will generate a two results (1st=left & 2nd=left+right).

The extra array sorting code is included to handle a large number of keys efficiently. Say for example; if someone had 1000 unique single-mouse-click checks for various reasons, the sorted array handles that large quantity efficiently.

For simplicity, you can ignore the code and just call the function:

ReturnValue = Single_MouseClick(Key as Integer)




Open MMORPG: It's your game!
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 6th Nov 2009 20:39
Interesting, I love it how you seem to write code that looks awfully complicated in codeboxes, but is so simple when actually looking at it in an IDE, or well... at least more simple.


EDP Map Editor[2D]
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 7th Nov 2009 03:06
I suppose if I wrote code in code boxes, it might be the other way around.


Open MMORPG: It's your game!
Aurum Knight
15
Years of Service
User Offline
Joined: 15th Jul 2008
Location: the suburbs of nowhere
Posted: 8th Nov 2009 04:02
Cool, this is pretty much what I use:


Wow Valle, that looks interesting, but I couldn't figure out what it does

Login to post a reply

Server time is: 2024-05-05 07:04:03
Your offset time is: 2024-05-05 07:04:03