Mouseclick problem (click limit on object)
by Vlad I · in Torque Game Builder · 11/17/2010 (4:33 pm) · 15 replies
I'm trying to find a way to limit clicking on an object to one.
When I press on BoxA it fades away and a sound is played, but since fading out is 3 seconds you can still press it as many times as you like and the sound effect will be played over and over again till the object is faded away completely and gets safedeleted.
How to limit the clicks on the object? I've been trying different ways and none seem to work here's one of ways I tried:
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
{ BoxA.setmouseclickslimit = 1;}
if(isObject(BoxA))
{
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
When I press on BoxA it fades away and a sound is played, but since fading out is 3 seconds you can still press it as many times as you like and the sound effect will be played over and over again till the object is faded away completely and gets safedeleted.
How to limit the clicks on the object? I've been trying different ways and none seem to work here's one of ways I tried:
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
{ BoxA.setmouseclickslimit = 1;}
if(isObject(BoxA))
{
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
About the author
#2
function BoxA::onMouseDown( %this, %mod, %worldPos, %mouseClicks )
{
if(%allow_click == 0)
{
$allow_click = 1;
schedule(600,0,"click_it");
}
}
function click_away()
{
$allow_click = 0;
}
It doesnt seem to work either. Is there a simple way just to limit to one click onMouseDown function?
11/18/2010 (5:14 am)
You mean smth like this?function BoxA::onMouseDown( %this, %mod, %worldPos, %mouseClicks )
{
if(%allow_click == 0)
{
$allow_click = 1;
schedule(600,0,"click_it");
}
}
function click_away()
{
$allow_click = 0;
}
It doesnt seem to work either. Is there a simple way just to limit to one click onMouseDown function?
#3
11/18/2010 (5:40 am)
Maybe get the timestamp of a click instead, and not responding to it unless a certain amount of time has passed is better. Set $lastClick, for example, to the value of getSimTime() and subtract last run from the current. Return without responding if not high enough.
#4
11/18/2010 (12:36 pm)
Just add the following as the first line of your onMouseDown callback. I think this should suit your needs. It works perfectly for my project and is quite simple:%this.useMouseEvents = false;
#5
I dont think this is valid, is it?
I tried to use it everywhere anyway no effect
Did you mean?
%this.SetUseMouseEvents = false;
11/18/2010 (2:24 pm)
%this.useMouseEvents = false; I dont think this is valid, is it?
I tried to use it everywhere anyway no effect
Did you mean?
%this.SetUseMouseEvents = false;
#6
I think these can be used interchangeably; I could be wrong though.
11/18/2010 (2:46 pm)
%this.useMouseEvents = false; and %this.SetUseMouseEvents(false);
I think these can be used interchangeably; I could be wrong though.
#7
it doesnt seem to work , and console doesnt show any errors
Here is what I used too:
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
if(isObject(BoxA))
{
%this.SetUseMouseEvents(false);
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
11/18/2010 (2:57 pm)
Hi Patrick againit doesnt seem to work , and console doesnt show any errors
Here is what I used too:
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
if(isObject(BoxA))
{
%this.SetUseMouseEvents(false);
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
#8
You're checking if BoxA is an object, but that's actually the class and I'm not sure if that will return true or false.
11/18/2010 (3:09 pm)
Is the callback ever executing the code?You're checking if BoxA is an object, but that's actually the class and I'm not sure if that will return true or false.
#9
11/18/2010 (3:11 pm)
hmm interesting let me check
#10
11/18/2010 (3:24 pm)
BoxA could also be the object name, if that's the case, try:BoxA.setUseMouseEvents(false);
#11
But yeah it is executing the code as I said the BoxA fades away and a click sound is played.
or btw I get this in gray color in console every time I click on the BoxA.
t2dSceneGraph::addToScene() - Object '1593' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1596' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1599' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1602' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1605' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1608' is already in a SceneGraph!.
11/18/2010 (3:36 pm)
I know what you menaBut yeah it is executing the code as I said the BoxA fades away and a click sound is played.
or btw I get this in gray color in console every time I click on the BoxA.
t2dSceneGraph::addToScene() - Object '1593' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1596' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1599' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1602' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1605' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1608' is already in a SceneGraph!.
#12
11/18/2010 (3:41 pm)
This is just a guess, but try using the onMouseUp callback instead of the onMouseDown.
#13
It does work as you first proposed. God damn TGB with their .dso files it was using cashed .cs.dso files all the time, unitll I deleted them all,(I think everyone comes accross that damn .dso problem)
here is the same code and it works wonders
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
if(isObject(BoxA))
{
%this.SetUseMouseEvents(false);
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
11/18/2010 (4:09 pm)
Patrick You are LEGEND !!!It does work as you first proposed. God damn TGB with their .dso files it was using cashed .cs.dso files all the time, unitll I deleted them all,(I think everyone comes accross that damn .dso problem)
here is the same code and it works wonders
function BoxA::onAdd(%this)
{
%this.setUseMouseEvents( true );
}
function BoxA::onMouseDown( %this, %modifier, %worldPosition, %mouseclicks )
if(isObject(BoxA))
{
%this.SetUseMouseEvents(false);
BoxA.startFade(); //fading behavior 3sec. then safedeleted
alxplay(BoxAclick);
}
#14
I can't tell you how many of hundreds of times I've had an issue with a cached dso...
Hope to see what you're working on sometime!
11/18/2010 (4:11 pm)
Happy to help Vladislav!I can't tell you how many of hundreds of times I've had an issue with a cached dso...
Hope to see what you're working on sometime!
#15
SetUseMouseEvents() is nice to know about. I have for some reason not done mouse-based stuff at all, and my current project isn't using it either. But one day, I tell ya…one day I might actually use mouse input!
11/19/2010 (4:01 am)
Haha, I have practically automated clearing the cache now (dragging it to the trash subconsciously), so it wouldn't be at the top of my mind either :PSetUseMouseEvents() is nice to know about. I have for some reason not done mouse-based stuff at all, and my current project isn't using it either. But one day, I tell ya…one day I might actually use mouse input!
Torque 3D Owner Ronny Bangsund
Torque Cheerleaders
What you could do is set an "isPlaying" sort of variable to true and return if it is already true, and schedule the setting of the variable to false again around the time it should be allowed to play again. Maybe it isn't the best way, but it should work.