Game Development Community

%this, %client, and %player ?

by XoCluTch · in Torque Game Engine · 08/21/2002 (11:58 am) · 5 replies

I have a Few questions about these stupid Var's, I have been having.. Ok what i am trying to do is when a player walks up to a console to spawn a vehicle i do this


function VehicleSpawnArea::onEnterTrigger( %this, %trigger, %obj )
{
%client = %obj.client;
%client.InVehicleSpawnArea = true;
}

Ok First off, What is this %this Var i thought it was the player, but it wasn't so i used %obj.client

ok all that works...

then i got this little bit of code on my menu

works something like this


function Menu::onWake(%client)
{
if ($ClientId.InVehicleSpawnArea == true)
Menu.InVehicleSpawnArea();
}

Now as u can see i have a var Which is something like %client being sent to this function when the menu opens, But it does Different From the Server's Version of %client So i was unable to use it.

So what i did was make a CommandToClient function Which sends %client var over and saves it as $ClientId on my Client Side, Well All and ALL this works Great Entill i try and play Multiplayer... then for some reason my Global Var isn't being set on the other player's that are joining


I have this:

game.cs - Server File
function GameConnection::createPlayer(%this, %spawnPoint)
{

// Store Client Id on Client Side as Global Var.
commandToClient(%this, 'StoreID', %this);

}


GameGui.cs - Local File
function clientCmdStoreID(%this)
{
$ClientId = %this; // Store Player ID Client Side Also As a Global Var
}

Ok so What is wrong here .. why is my Global Var not being set for other players joining the server... And also why are all these %client %this and %player Var Different??? Shouldn't they all be the same??
I have used Echo and Error Messages to check what they are and sometimes they are the same but sometimes they are different... They are always a number like 1331 or something.. I never had a problem using these Var's entill i started trying to use the Onwake(%client) var ... which seems as tho it's really not %client even tho tons of example code have it using it like that...


Thanks

#1
08/21/2002 (12:30 pm)
oh and in this function:

function clientCmdStoreID(%this)
{
$ClientId = %this; // Store Player ID Client Side Also As a Global Var
}


i did this

function clientCmdStoreID(%this)
{
$ClientId = %this; // Store Player ID Client Side Also
error(%this);
error($ClientId);
}


And on BOTH computers these numbers are the same.. Why shouldn't they be?

So I assume $ClientId Is being set on both computers, Only the Second one's var set from the entering the Trigger isn't being passed
#2
08/21/2002 (12:44 pm)
Ok something just came to me...

Will $clientId act like a Copy of %client

and whatever changes i make to $clientId will also happen to %client or will it only effect it's Self and not Change anything in %client... and Vice Versa


Nm i checked this and its not the problem...

this is starting to make me mad
#3
08/21/2002 (1:32 pm)
bah, i couldn't figure out what was wrong, but i made a temp fix for it ... i just made some commandtoclient functions and took the if statement out... and it works fine now... just more wasted code now.. when only a few line should have been enough
#4
08/22/2002 (12:52 am)
%this refers to the thing before the scope resolution operator (the "::").

%obj usually refers to the player object involved. This is the actual object the player is controling that you can see in the world. It changes as the player gets in and out of vehicles and dies/respawns.

%client or %obj.client is the players client id which itentifies that players connection to the game. It stays the same as long as they are connected to the server. So if you set variables under it (ie %client.isinvehiclezone = true ) you will have to worry about resetting those when the player gets killed.
#5
08/22/2002 (12:58 am)
Also, if you forget to include the variable %this in when using the scoping operator for functions, ::, then you'll be off a parameter, which you have noticed.

Another thing. You can access %player and %client several different ways, including getting passed the vars themselves or via %player.client or %client.player as well.