Player variable from script
by Gordon Marsh · in General Discussion · 07/10/2006 (11:16 am) · 7 replies
All,
Sorry I know there are a number of threads that scout around this issue, but none seem to have a straight answer.
I have just added a ConsoleMethod and corresponding method to my player.cc file. Now I would simply like to be able to call the function from torque script in the following manner:
currentPlayer.newfunction();
But what should currentPlayer be? i.e. how do I get a handle to the player from script?
Thanks,
TheGords
Sorry I know there are a number of threads that scout around this issue, but none seem to have a straight answer.
I have just added a ConsoleMethod and corresponding method to my player.cc file. Now I would simply like to be able to call the function from torque script in the following manner:
currentPlayer.newfunction();
But what should currentPlayer be? i.e. how do I get a handle to the player from script?
Thanks,
TheGords
#2
just use the global variable $Player.
... oh, wait that variable doesn't exist in stock TGE.
basically in GameConnection::initialControlSet(%this),
add some lines like this:
.. this may not be the 'right' way to do things, but it's been very useful for us.
07/10/2006 (1:19 pm)
Or, if you're trying to get the player on the client side,just use the global variable $Player.
... oh, wait that variable doesn't exist in stock TGE.
basically in GameConnection::initialControlSet(%this),
add some lines like this:
$player = %this.getControlObject();
.. this may not be the 'right' way to do things, but it's been very useful for us.
#3
Orion, with your solution where do you declare 'player'? If I add as a global variable in the gameconnection.cc file, I get a lot of compiling errors as it appears to clash with other files variables.
Thanks again...
07/10/2006 (4:09 pm)
Thank you both for your suggestions.Orion, with your solution where do you declare 'player'? If I add as a global variable in the gameconnection.cc file, I get a lot of compiling errors as it appears to clash with other files variables.
Thanks again...
#4
07/10/2006 (4:34 pm)
@Gordon: he means declare that in script. The GameConnection::initialControlSet is in client/scripts/serverConnection.cs.
#5
you don't need to declare script variables, even global ones.
you'll find the function GameConnection::initialControlSet() in .../client/serverConnection.cs. just add the code in.
let me know if that works for you.
edit: doh! beat me to it, rubes !
07/10/2006 (4:36 pm)
Hey Gordon -you don't need to declare script variables, even global ones.
you'll find the function GameConnection::initialControlSet() in .../client/serverConnection.cs. just add the code in.
let me know if that works for you.
edit: doh! beat me to it, rubes !
#6
07/10/2006 (4:37 pm)
By mere minutes!
#7
07/10/2006 (5:01 pm)
Thanks guys, that works like a charm! Think I need to improve my knowledge of Torque function locations!
Torque 3D Owner Rubes
...something along those lines. For a game with only one client, you can just use 0 as above.