Game Development Community

Return value from serverCmd

by Robin Rudick · in Torque Game Engine · 09/16/2006 (10:33 pm) · 5 replies

Ive been trying to get a simple way of getting the players location

i did this by making a simple command

function serverCmdPlayerPosition(%client)
{
return %client.player.getPosition();
}

now the issue is, all of a sudden. it stopped working. it was working fine, i could do anything with the command to get the players position. it might be something simple im missing, but it looks fine to me. if anyone knows why id sure like to know

#1
09/16/2006 (10:46 pm)
Server Commands are not designed to have a return value. You need to do all of your processing in that command, so if you want to display it, you would do:

function serverCmdPlayerPosition(%client)
{
     echo(%client.player.getPosition());
}

If you want to actually send that value back to the client, you need to send it with a clientCmd:

function serverCmdPlayerPosition(%client)
{
     commandToClient(%client, 'playerPos', %client.player.getPosition());
}
#2
09/16/2006 (10:53 pm)
Well i want a return value not just an echo out

i had this working before i change anything, so i know it does work, not sure why it stopped working tho.

function serverCmdPlayerPosition(%client)
{
%player = %client.player.getPosition();
return %player;
}
#3
09/16/2006 (10:55 pm)
Ohhhh. i figured it out

i had changed the code that way, and had it all setup to process everything inside of those scripts so what i think had happen is there was an error in my code, so rather then get this working, i just had those other functions hardwired up working

resulting in it being very misleading
#4
09/17/2006 (10:19 am)
Synchronous RPC is a very dangerous thing. You will typically run into one of two problems: deadlocks, or poor performance (or both :-)

In general, you need to structure all your interaction as state machines, where a request to the server puts you in a state where you're waiting for a response, and when the response comes, you go to some other state (based on that response).
#5
09/17/2006 (2:35 pm)
@JW is totally correct (this is how mission loading across a networked connection works, for example).

Robin, your second statement is correct as well---there is no way to return a value using the return statement back to a client, so your results must have been misleading you.