Game Development Community

Help with onMouseDown

by Bruno · in Torque Game Builder · 02/13/2007 (2:53 am) · 2 replies

Hi,

In my game i can't allow the player to keep pressing the mouse button, there has to be a little pause between each time the player is allowed to click the mouse.
So, i did something like this :

function sceneWindow2D::onMouseDown( %this, %mod, %worldPos, %mouseClicks )
{
if(%allow_click == 0)
{
$allow_click = 1;
schedule(600,0,"click_it");
}
}


function click_away()
{
$allow_click = 0;
}


This works quite nice, but if i start clicking very fast after a while, 4 or 5 seconds it's like the schedule instead of working with the value of 600, works with 0 or something, as it allows the player to click and screws up the game.

Any other ideias on how to do this ?

thanks,
Bruno

#1
02/13/2007 (3:10 am)
Hi.
Try using getsimtime(). This function gives you the simulation time in milliseconds.
When you recognize a valid click save the simtime in a global variable.
When the user clicks again, compare the actual simtime with the saved one and if the difference is less than 600 milliseconds, discard the click.
If the difference is 600 or more, save the last getsimtime result and do what you need to do.

Hope this helps!

Bye,
Jacopo

edit: corrected the pause value... :)
#2
02/15/2007 (3:02 pm)
The problem is probably that you are creating multiple schedules that are all running at the same time and then allowing mouse clicks again. You can store the schedule's ID and then only create a new one if it is !isEventPending

Either way, you could at least use that to see if you're trying to create a schedule when there's already one that will do the same thing shortly.

Hope that made sense ;)