Game Development Community

Two player control, single set of movement functions

by Christopher Wolfe · in Torque Game Builder · 10/21/2005 (3:01 pm) · 3 replies

I'm 100% completely new to programming, so even though I know what I want to do I'm not sure how to do it.

Following what was mapped out in the tutorial I wanted to add controls for a second player. I got it to work, but the way I went about it was to set up two separate move functions(player1Up() and player2Up(), for example) and two separate action maps for keyboard bindings. What I want to be able to do is, within the action map key bindings, send a little variable down to the movement functions so that I only need one set total. For example, and this isn't real code so work with me...

$player1.bind(keyboard, "w", "playerUp ( player1 variable );");

and

$player2.bind(keyboard, "w", "playerUp ( player2 variable );");

...and that variable passes to

playerUp (whoeverIsMoving)
{
whoeverIsMoving.setVelocityX ( 10 );
}

I'm absolutely certain that this is an easy problem that anybody with some general programming knowledge can remedy. I, however, am not there yet.

Thanks in advance!

CW

About the author

Recent Threads


#1
10/21/2005 (3:32 pm)
PlayerUp ("$player1")

and

playerUp("$player2")

and then

playerUp(%whoeverIsMoving)
{
eval(%whoeverIsMoving @ ".setVelocityX (10);");
}

Basically you build the string using @ to 'concatenate' the two parts of it together, and the eval() function executes the command in that string. I think that should work.
#2
10/22/2005 (12:55 pm)
My question is completely different from what the original question is but why do you use

eval(%whoeverIsMoving @ ".setVelocityX(10);");

rather than

%whoeverIsMoving.setVelocityX(10);


Does it matter? Just wondering why you chose one over the other.
#3
10/22/2005 (1:29 pm)
*shrug*

does that work? Then yeah that's easier isn't it. :)