Game Development Community

Determining whether mouse button is up or down

by Steve Montgomery · in Torque Game Engine · 04/29/2006 (9:21 am) · 5 replies

I implemented the code in C2's sniper scope example, and I notice that I get two mouse events for every button press. That is causing the scope to zoom out when I release the button.

I can put an ugly hack in there to fix it, but I wanted to understand how it works. First of all, is there a way to determine if the script function is being called because the the mouse button is down or up? Second, is there a way to force the event to fire only on the mouse being pressed?

BTW, thanks for the code C2.

#1
04/29/2006 (9:41 am)
I posted the solution as a comment for this a while ago, it should work fine.
#2
04/29/2006 (9:52 am)
Are you talking about the code in the last part of your post? I had a problem with it at first, but I found my mistake. It works now.

If I understand what you are doing, you are basically trying to ignore the button release by only executing the code every other event. I can make that work, but I am worried about the state machine loosing its sequence. I am not familiar enough with the engine.

I still want to understand if there is a way to determine whether an event is being called because of a button/keypress or a button/key release. I am sure I am going to need that in other parts of my design.

Thanks for the help C2. That is twice now. Do you ever sleep?
#3
04/29/2006 (12:28 pm)
He is using the up/down events. The %val parameter passed into the a keyboard/mouse initiated function returns 1 when a key is pressed and 0 when a key is released.
#4
04/29/2006 (1:59 pm)
Very cool. Thanks a lot.

EDIT:

Actually, I am looking at his code. If %val determines the button state, then why did his original code block not work? He was testing for it there. He still had to put the code in to toggle internal states to make it work.
#5
04/29/2006 (2:10 pm)
NEVERMIND!!!

I did not read the code right. Geez. I see what is going on now. The only time that the zoom is toggled is when %val is 1, meaning the button is pressed. If val is zero, nothing. You would think I had never looked at code before. Oh well.

Thanks Paul and C2!