Game Development Community

MouseDown issues

by Teromous · in Torque Game Builder · 02/26/2008 (1:38 pm) · 18 replies

Right now I'm just trying something basic, which would echo whenever the user click the left mouse button. I know there are resources on this, which is where I got my code from, but it doesn't seem to work. Here's the code I used:

This is in the level loading script:

function t2dSceneObject::onLevelLoaded(%this, %scenegraph)
{
// make sure the scene window is set to send mouse events to objects
if(!sceneWindow2D.getUseObjectMouseEvents())
{
sceneWindow2D.setUseObjectMouseEvents(true);
}

// set this object to accept mouse events
%this.setUseMouseEvents(true);
}

This is in a separate script which will be expanded on later

function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
echo("works");
}

...and drumroll...nothing happens.

#1
02/26/2008 (2:02 pm)
For your onMouseDown function, replace sceneWindow2D with t2dSceneObject. You are setting up to capture object mouse events in onLevelLoaded but are trying to tie it to a window mouse event callback.
#2
02/26/2008 (2:26 pm)
function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
    echo("works");
}

That one.
#3
02/26/2008 (3:16 pm)
I replaced:
function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
echo("works");
}

With:
function t2dSceneObject::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
echo("works");
}

But still no echo. Clicking all over the screen and absolutely nothing.
#4
02/26/2008 (4:48 pm)
Ah this is driving me nuts! I don't care how this is done, I just want to be able to get some sort of feedback when the mouse button is clicked and none of the resources or forum posts work.
#5
02/26/2008 (5:35 pm)
Well this is odd...I tried doing this:


function Action()
{
t2dsceneobject::onMouseDown(%worldPosition);
echo(%worldpostion);
}

...then making a GUI that I could press the button to call the function, and it worked. Well it sort-of worked. It called the function t2dSceneObject::onMouseDown. I guess I misunderstood the function. I thought that using:

function t2dSceneObject::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
echo("works");
}

...would make it so that whenever I hit a mouse button, it would echo. I guess I'll keep working with this until I can do something with it. I'm so used to using the A6 engine where it isn't so complicated. Sometimes I wish I could just merge attributes of multiple engines.
#6
02/26/2008 (6:19 pm)
Just realized that using t2dsceneobject::0nMouseDown(%worldPosition); INSIDE a function would be the same thing as calling a function...and thus it really isn't working...

Back to the drawing board...
#7
02/26/2008 (6:31 pm)
Do you have any scene objects on the scene at all? You will only get a successful echo if you click on a scene object loaded into the scene.

If you want to be able to click anywhere use the scenegraph instead of a scene object.
#8
02/26/2008 (6:55 pm)
Tried all of these:

function t2dSceneObject::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{

echo("WORK!");

}
function PlayScreenGui::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{

echo("WORK!");

}
function SceneWindow2D::onMouseDownfunction(%this, %modifier, %worldPosition, %clicks)
{

echo("WORK!");

}
function SceneGraph2D::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{

echo("WORK!");

}
function t2dSceneGraph::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{

echo("WORK!");

}

...none of them work.
#9
02/26/2008 (8:19 pm)
I really hope you are exec'ing the file containing all of these functions.
#10
02/27/2008 (3:35 am)
Yeah everything is executed in my game.cs file and there were no errors listed in the console, but I get no echo.
#11
02/27/2008 (4:20 am)
Sometimes I think the onMouse callbacks are fickle. Sometimes using the name in the namespace works, sometimes it does not. What I do know works all the time is using the class in the namespace. Try that.
#12
02/27/2008 (6:23 am)
I've never had a problem with them. Why don't you post your project someplace so we can download it and look through it. From what I've seen, you're probably doing something rather small wrong.
#13
02/27/2008 (9:13 am)
I'm doing all my changes in TGB Adventure Kit if any of you guys have it. That's all I'm trying to modify, but I can't seem to get it to work.
#14
02/27/2008 (9:18 am)
Check the gui file where sceneWindow2d is being created and make sure it has the useWindowMouseEvents = "1" set properly. Also make sure you are not pushing another GUI on top of the mainScreenGui.

I use the onMouseDown all the time for a scenWindow.

//**** In mainScreen Gui

new t2dSceneWindow(sceneWindow2d) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "0";
   };


function sceneWindow2D::onMouseDown(%this, %mod, %worldPosition, %mouseClicks)
{
   if ( %this.getSceneGraph().getScenePause() == true ) return;
   
   playSound(buttondownAudio); 
   $smash_attempts++;
   if ( checkMiss(%worldPosition) )
   {
      //echo("You Missed");     
      $smash_misses++; 
      $health_score -=5;
      %checkmiss_icon = new t2dStaticSprite(){scenegraph = SceneWindow2D.getScenegraph();class = checkMiss;};
           
      %checkmiss_icon.setImageMap("CheckMissImageMap");
      %checkmiss_icon.setSize("35 31");            
      %checkmiss_icon.setTimerOn(2);
      %checkmiss_icon.setPosition(%worldPosition);
      playSound(missAudio);
      $SPEED_BONUS_TIME_START = 0;
      $SPEED_BONUS_TIME_END = 0;
      $SPEED_BONUS_COUNT = 0;
      //%this.sceneGraph.incMissedCount();
   }
   
}
#15
02/27/2008 (10:11 am)
Yeah I forgot to mention that I set both
useWindowMouseEvents = "1";
useObjectMouseEvents = "1";

Just in case. Still trying to get it to work.
#16
02/27/2008 (10:24 am)
You may want to consider createing a blank test project and see if you can get it working on that first before experimenting with the Adv Kit.
#17
02/27/2008 (11:22 am)
I got it to work on a blank project, but no such luck with Adventure Kit.
#18
02/27/2008 (12:30 pm)
I figured out what was causing this not to work:

new t2dSceneWindow(EffectWindow) {
canSaveDynamicFields = "0";
Profile = "GuiContentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
lockMouse = "0";
useWindowMouseEvents = "1";
useObjectMouseEvents = "1";
};

...is added below the t2dSceneWindow(sceneWindow2D). In another thread I found where a player was having problems with onMouseMove, one of the guys there recommended removing the effectwindow. I also found that using:

function EffectWindow::onMouseDown(%this, %mod, %worldPosition, %mouseClicks)
{
echo("test");
}

...worked. Thanks for your help guys, it's hard enough to code something by yourself, let alone look through somebody else's code and make changes. THANK YOU GUYS!