Game Development Community

i know this sounds basic but...

by rennie moffat · in Torque Game Builder · 03/08/2010 (12:28 pm) · 2 replies

I have this bit of code which is perplexing me, essentially it is a maze game where a player, is moved by mouse events. The player will only move if the mouse up is on an object (the behavior owner) which is either inline with the X or the Y axis. So that works, I have set up a condition that of the player selects a destination which is not directly in line with the players x or y axis that a "false roll over appear", a basically a thud, telling the player he can not move there. It is represented by a sceneObject/static sprite. The trick is, I want the "false roll over" to dissapear, so I put it on a schedule as you can see but the call to move the roll over to the wait pos is not working, the roll over remains.




ffunction floorBlockBehavior::onMouseDown( %this, %mod, %worldPos, %mouseClicks)
{
///if the owner is selected (mouseDown) but it does not line up with the x and y axis of the player a "false roll over" is put over the owner. then a schedule so that the false roll over leaves. This schedule call does not currently work and i am unsure why.
	if($playerPositionX != %this.positionX && $playerPositionY != %this.positionY)
	{
		%this.floorBlockFalse.setPosition(%this.positionX, %this.positionY);
		%this.schedule(500, moveToWait);
	}
	
	if($playerPositionX = %this.positionX || $playerPositionY = %this.positionY)
	%this.floorBlockRo.setPosition(%this.positionX, %this.positionY);
}

function floorBlockBehavior::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{	
	if($playerPositionX != %this.positionX && $playerPositionY != %this.positionY)
	{
		return;	
	}
	
	%this.mouser.moveTo(%this.positionX, %this.positionY, %this.velocity, true);
	%this.floorBlockRo.setPosition(%this.positionX, %this.positionY);	
}

function floorBlockBehavior::moveToWait(%this)
{
	%this.floorBlockFalse.setPosition(%this.waitPos);
}

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
03/09/2010 (12:34 am)
Without knowing what you put into the "waitPos" field of your behavior, I don't think anybody will be able to answer this. Also, you should have put an echo statement inside the "moveToWait" function to make sure that it got called.

Also, you are using the assignment operator inside your if-statement at Line 10 when I think you mean to use the equal-to comparison operator.

Finally, it looks like you may not have considered what to do when the user clicks down on an invalid spot, but drags the mouse over to another invalid spot. You appear to ignore the mouse up event when the position is invalid, but there is no "thud" to let the user know that.
#2
03/09/2010 (6:06 am)
hmm. thank you.