Conflicting Mouse Events
by Romulo Diniz Filippini · in Torque Game Builder · 04/12/2011 (1:09 pm) · 6 replies
Hi,
I've been trying to build an event where the mouse clicks should close gui windows when open, for the dialog system. But it's conflicting with another event where the mouse clicks move the Player to the point clicked.
Here the two code snippets:
Player Movement:
Close Dialog Windows:
I know that the conflict is because sceneWindow2D namespace, since I've managed to make it work by disabling the player movement event. But I don't know how to make mouse events without using sceneWindow2D namespace =/
Could you guys help me with this?
Att
Romulus
I've been trying to build an event where the mouse clicks should close gui windows when open, for the dialog system. But it's conflicting with another event where the mouse clicks move the Player to the point clicked.
Here the two code snippets:
Player Movement:
function sceneWindow2D::OnMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
if($cine2 == true)
return;
$Player.playAnimation( "lilithwalk2Animation" );
$Player.moveTo($currentMouseX, $currentMouseY - 10, 30, true, true, true);
}Close Dialog Windows:
function sceneWindow2D::onMouseDown(%this, %mod, %worldPos, %mouseClicks)
{
if ($lvl1dialogWindowOpen == true)
{
echo("dialog SPC is SPC open!");
Canvas.popDialog(LilithDialog);
$lvl1dialogWindowOpen = false;
}
else
return;
}I know that the conflict is because sceneWindow2D namespace, since I've managed to make it work by disabling the player movement event. But I don't know how to make mouse events without using sceneWindow2D namespace =/
Could you guys help me with this?
Att
Romulus
#2
04/14/2011 (6:53 pm)
Many thanks for the answer, and you are right, it is better to start re-organizing these mouse functions now or I'll regret it later. I just put everything related to mouse interaction in an main script and put a bunch of IFs so I can control it easly with variables.
#3
04/16/2011 (9:54 pm)
If you have a whole bunch of "If/Else If" statements then you may want to look into using "Switch/Case" instead. It is easier to read, and keep organized.
#4
The first dialog window opens but the second doesn't open, Am I forgetting something?
04/17/2011 (5:51 am)
My code is this until now://This function is to close the dialog windows with mouse clicks.
function scenewindow2D::onMouseDown(%this, %mod, %worldPos, %mouseClicks)
{
if (lilithDialog.isAwake())
{
lilithChat();
}
if (!isEventPending(%this.lvl1cinePart1schedule))
lvl1cinecont2();
}
//Function to open and close Dialog Windows.
function lilithChat(%this)
{
// open the options menu up!
if(!lilithDialog.isAwake())
{
Canvas.pushDialog(lilithDialog);
return;
}
Canvas.popDialog(lilithDialog);
}
//Timed events 1.
function level1::onLevelLoaded(%this, %scenegraph)
{
schedule(2000, 0, lv1setCineText1);
%this.lvl1cinePart1schedule = schedule(2000, 0, lilithChat);
}
//Timed events 2.
function lvl1cinecont2()
{
schedule(2000, 0, lv1setCineText2);
%this.lvl1cinePart2schedule = schedule(2000, 0, lilithChat);
}The first dialog window opens but the second doesn't open, Am I forgetting something?
#5
The %this in onLevelLoaded will be an object... seemingly from your "level1" class?
The %this in onMouseDown will be a sceneWindow2D that received the mouse event.
So the "%this.lvl1cinePart1schedule" that you're checking is a different variable name than the one you're setting.
I'm not even sure what the %this in your lvl1cinecont2() function would turn out to be!
04/17/2011 (9:30 am)
It looks like you're mixing %this variables?The %this in onLevelLoaded will be an object... seemingly from your "level1" class?
The %this in onMouseDown will be a sceneWindow2D that received the mouse event.
So the "%this.lvl1cinePart1schedule" that you're checking is a different variable name than the one you're setting.
I'm not even sure what the %this in your lvl1cinecont2() function would turn out to be!
#6
04/17/2011 (3:23 pm)
I use an proper ID for the schedules instead of %this, like you advised. It worked wonders mr Tim, now my only problem is that the past events keep playing over and over, after the cycle is finished. I´ll try to figure out why.
Torque 3D Owner Tim Scheiman
Ghost Ship Studios
If so, you could easily throw the window code into the mouseup function with the player stuff... and just return after that if your lvl1dialogWindowOpen variable is true (skipping the player stuff entirely).
I'm not sure either of them belong in the sceneWindow2D namespace? You'll end up with a massive switch statement (over HUD, in inventory, in dialogue window, on character, on enemy, etc. etc.) if you go that way...
I code like that too sometimes. :)