Game Development Community

Passing data to server, to show on console

by Jason Wee · in Torque Game Engine · 01/22/2011 (8:03 pm) · 2 replies

How do you guys pass data to your server so that it can use the string/numbers to do condition? Im using starter.fps for this. Below is what i have tried. Help please!

In starter.fps\server\scripts\game.cs


//CUSTOM
function GameConnection::joinPlayerClass(%this, %classid)
{
$hihi = %classid;

}

function onServerCreated()
{
....
echo("global is: " @ $hihi);
}

====================================================================================================

In starter.fps\server\scripts\commands.cs


//CUSTOM
function joinclass(%classid)
{
commandtoserver('JoinPlayerClass', %classid);
}

function serverCmdJoinPlayerClass(%client, %classid)
{
%client.joinPlayerClass(%classid);
}

#1
01/23/2011 (9:11 am)
While that looks visibly correct I don't think you'll actually see a proper echo in you onServerCreated() because the global isn't actually set until you joinPlayerCLass(). Depends on how you set up the player selection and mission start procedures...
#2
01/25/2011 (12:19 am)
My understanding is that you're making a class selection system (from a GUI or whatever else, doesn't specifically matter) and need to pass the class ID to the server when the client makes the selection.

Before I go on I should point out that using a global to store the class ID will only work out if you're making a single player game. If you have more than 1 player in the game, they'll all be sharing that one global since it's on the server. If this is single player then you can ignore this issue. If not, I'd suggest storing as something like %this.playerClass (if called from within GameConnection::joinPlayerClass where "%this" is the client).

Now as far as the commandtoserver usage... you have a call to a commandtoserver in a server script, which isn't going to work out. The function "joinclass(%classid)" needs to be in a client script, from which it can call "commandtoserver('JoinPlayerClass', %classid);" to send %classid to the server.

I don't know specifically how your system works, but as a simple test I would put the joinclass function in (this path might not be 100% accurate, I haven't used TGE for some time): client\scripts\default.binds.cs
...and then just call it from the console in-game (~) like this:
joinclass(2);
...or any other number since this would just be a test.

That should make this work, however as Michael said it seems highly unlikely that any of this could have happened before onServerCreated (though I also have no idea how it's set up and could be wrong), so you're still unlikely to get anything out of that echo. I'd put the echo into "GameConnection::joinPlayerClass" so it's printed as soon as the operation completes.