Game Development Community

why won't this work?

by rennie moffat · in Torque Game Builder · 09/10/2009 (11:11 pm) · 14 replies

function cube::onLevelLoaded
{
	%this = cube;
	%this.setUseMouseEvents(true);
}

function cube::onMouseUp(%this, %worldPos, %clicks, %modifier)
{
	%this.setPositionTarget(%targetX, %targetY, [%autoStop = true], [%callback = false], [%snap = true], [%margin = 0.1]);
}

function cube::moveCubeToTarget(%this)
{
	%this.moveTo(%targetX, %targetY, %speed, [%autoStop = true], [%callback = false], [%snap = true], [%margin = 0.1]);
}


I have enabled mouse events in the game.cs, classed it properly, tried everything. My logic tells me this should work, but it does not. Such a simple step but no dice.


:?

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
09/10/2009 (11:39 pm)
That first one should be
function cube::onLevelLoaded(%this)
{  
    %this.setUseMouseEvents(true);  
}
#2
09/11/2009 (12:15 am)
Try changing

function cube::onMouseUp(%this, %worldPos, %clicks, %modifier)
{
   %this.setPositionTarget(%targetX, %targetY, [%autoStop = true], [%callback = false], [%snap = true], [%margin = 0.1]);
}

function cube::moveCubeToTarget(%this)
{
   %this.moveTo(%targetX, %targetY, %speed, [%autoStop = true], [%callback = false], [%snap = true], [%margin = 0.1]);
}

to

function cube::onMouseUp(%this, %worldPos, %clicks, %modifier)
{
   %targetX = 100;
   %targetY = 100;
   %this.setPositionTarget(%targetX, %targetY, true, false, true, 0.1);
}

function cube::moveCubeToTarget(%this)
{
   %targetX = 100;
   %targetY = 100;
   %speed = 50;
   %this.moveTo(%targetX, %targetY, %speed, true, false, true, 0.1);
}

#3
09/11/2009 (1:42 am)
@ Dan,
oops, I missed that but noticed after, still no dice re: (%this, %scenegraph).



@aun
The only problem is, I want my target to be depending on where I click. The way you have wrote it, won't this make it impossible but to be at x100, y100? Why would you set the x and y at 100, what is you logic?

Regardless, I tied yours and no dice again. I am perplexed. Seems like this should be a very simple thing.




Beyond enabling mouse events to true in onLevelLoaded, are there scripts that need to be checked in order to insure mouseEvents? I read about checks in the mainScreen.gui, and in game.cs. I did make adjustments here too, but nothing. Very puzzling.
#4
09/11/2009 (2:29 am)
@Rennin, there's no logic there. I just wanted to fix your script compiling error.

If you want your object to move to where the mouse clicks. Here's what you have to do.

function sceneWindow2D::onMouseUp(%this, %worldPos, %clicks, %modifier)
{
   %targetX = getWord(worldPos, 0);
   %targetY = getWord(worldPos, 1);
   $yourCudeId.moveTo(%targetX, %targetY, true, false, true, 0.1);
}

Move the onMouseUp to the SceneWindow2D gui so it can catch the callback on the entire screen.

And be sure that you have assign the "$yourCudeId" variable with your cube id.
#5
09/11/2009 (9:07 am)
Oh right, it would make more sense to call the sceneWindow2d since I'm not actually clicking on the cube, right! thanks.

But I do have a couple of questions for you,
"$yourCudeId" = $cube?


also, I need to study more on the getWord, but essentially I believe (correct me if I am wrong) but it is simple calling "worldPos" in this instance? Also the 0 and 1 represent the different possibilities, as in, if this were 3D, I would have 0,1,2? correct?

Thanks.

Ren

#6
09/11/2009 (1:15 pm)
Rennie,

The getWord() method simply parses a string out into its individual words.

For Example:

If I have a string like %Position = "100 200";

Then to get the first word you would call: getWord(%Position,0) which would equal the string "100"

and to get the second word you would call: getWord(%Position,1) which would equal the string "200"


Keep in mind you can do this with anything, not just numbers:

%Sentence = "This is a Sentence"

getWord(%Sentence,0) would equal "This"
getWord(%Sentence,1) would equal "is"
getWord(%Sentence,2) would equal "a"
getWord(%Sentence,3) would equal "Sentence"
#7
09/11/2009 (1:18 pm)
oops.. sorry, didn't realize that people have already answered this for you in another thread
#8
09/11/2009 (1:44 pm)
yes sorry I posted in there. but thank you. just clearing some stuff.
#9
09/11/2009 (2:42 pm)
@ Kenneth
So regarding your answer, the getWord is necessary as it will, in this case link %postion to a defined amount.
#10
09/15/2009 (11:53 am)
@ Aun,
Hi, I have tried your code but with no avail, it does not work. I am wondering if you have any thoughts on this.
function cube::onLevelLoaded (%this, %scenegraph)
{
	$cube = %this;
	%this.setUseMouseEvents(true);
}

function sceneWindow2D::onMouseUp(%this, %worldPos, %clicks, %modifier)  
{  
   %targetX = getWord(worldPos, 0);  
   %targetY = getWord(worldPos, 1);  
   $cube.moveTo(%targetX, %targetY, true, false, true, 0.1);  
}


my only doubt is that the $cube.moveTo command is in the sceneWindow2D class. But since $cube is global I don't think it is a conflict of interest.





#11
09/18/2009 (12:41 am)
@rennie Change

%targetX = getWord(worldPos, 0);    
%targetY = getWord(worldPos, 1);

to

%targetX = getWord(%worldPos, 0);    
%targetY = getWord(%worldPos, 1);

I mistype that in my original post, sorry about that. Good luck!

www.mayansoftware.com
#12
09/18/2009 (1:27 am)
I've just gone over this quickly tonight, as I am about to wrap it up, but I made the changes, sorry I didn't spot that earlier. I did pop this full code into the complier and it does not work. The only part I think that their may be some conflict in my classing. I know we thought, on your advice, call the sceneWindow2D, makes sense to me, but then that worldPos should be passed on to the cube.

I popped in your code tho and it did not work. I played with a bunch of versions, I was concerned about class, and made a new function cube::cubeMove where I called targets and used the moveTo command, but no avail either. Also swapped positions of target and worldPos in your onMouseUp, thought that might work, along with a bunch of other stuff but no dice.

My cube is classed as cube. The only confusion/doubt I have is the sceneWindow2D, does this need to be classed, it cant tho can it.



hmm... thoughts?




function sceneWindow2D::onLevelLoaded(%this)
{
%this.setUseWindowMouseEvents(true);
}

function cube::onLevelLoaded (%this, %scenegraph)
{
	$cube = %this;
	%this.setUseObjectMouseEvents(true);
}

function sceneWindow2D::onMouseUp(%this, %worldPos, %clicks, %modifier)  
{  
   %targetX = getWord(%worldPos, 0);  
   %targetY = getWord(%worldPos, 1);  
   $cube.moveTo(%targetX, %targetY, true, false, true, 0.1);  
}
#13
09/18/2009 (12:03 pm)
I'm not sure if sceneWindow2d would bother if any kind of scenegraph has just been loaded.

Try to add
sceneWindow2d.setUseMouseEvents(true);
inside cube's onLevelLoaded method. (It's just quick thought - I'm not even convinced that sceneWindow2d has setUseMouseEvents method, but it was posted earlier).

One more thing - check your console (tilda/~) and console.log often - you would find there many of common mistakes you may make announced. Especially those when you use methods that object does not have.

Cheers!
#14
09/18/2009 (1:45 pm)
Thanks I will check this out in a bit, about to tackle a different problem.





cheers.
ren