Server/Client Functions
by Chris "C2" Byars · in Torque Game Engine · 05/07/2006 (2:59 pm) · 4 replies
Any pointers (or full solution) to getting this action away from global variables so it works networked correctly?
On the client side we have a small function to say its okay to pick up a weapon.
On the server side, we have the big old collision/pickup code that checks to see if $Pickitup equals one or zero (in Armor::onCollision), and does the correct action depending on what it gets. The bolded is basically all you need to see to see the problem. I need another way to do this without using the nice dollar sign.
Any and all aid is greatly appreciated, as always. :)
On the client side we have a small function to say its okay to pick up a weapon.
function pickupitem(%val)
{
if (%val)
$Pickitup = 1;
else
$Pickitup = 0;
}
moveMap.bind(keyboard, "x", pickupitem);On the server side, we have the big old collision/pickup code that checks to see if $Pickitup equals one or zero (in Armor::onCollision), and does the correct action depending on what it gets. The bolded is basically all you need to see to see the problem. I need another way to do this without using the nice dollar sign.
%curWeapon = %obj.getMountedImage($WeaponSlot).item.getName();
if (%col.dataBlock.className $= "Weapon")
{
[b]if ($Pickitup == 1)[/b]
{
if (%curWeapon $= %col.dataBlock)
{
//don't pick it up
}
else if (%obj.getInventory(%col.dataBlock) > 0)
{
//don't pick it up
}
else
{
%obj.setImageTrigger(0,false);
%image = %obj.getMountedImage($WeaponSlot);
%obj.throw(%image.item);
%obj.pickup(%col);
%obj.client.clearWeaponInformationHud();
}
}
else if (%curWeapon $= %col.dataBlock)
{
//don't display message
}
else if (%obj.getInventory(%col.dataBlock) > 0)
{
//don't display message
}
[b]else if ($Pickitup == 0)[/b]
{
%obj.client.setWeaponInformationHud(%col.dataBlock.pickupName);
if (%obj.pendingPickupScheduledEvent)
{
cancel(%obj.pendingPickupScheduledEvent);
}
else
{
}
%obj.pendingPickupScheduledEvent = %obj.schedule(1000, UpdateWeaponInformation);
}
}Any and all aid is greatly appreciated, as always. :)
#2
Each time I press the button.
Edit: Fixed it. Using a different variation.
05/07/2006 (5:01 pm)
Remote Command Error - command must be a tag.
Each time I press the button.
Edit: Fixed it. Using a different variation.
function pickupitem(%val)
{
if (%val)
CommandToServer('pickitup');
else
CommandToServer('dontpickitup');
}
moveMap.bind(keyboard, "x", pickupitem);function serverCmdpickitup(%client)
{
%client.pickitup = 1;
}
function serverCmddontpickitup(%client)
{
%client.pickitup = 0;
}
#3
is called a tag and is handled more efficiently by the net stuff, which is why commandToClient/Server has to be a tag.
Ian
www.mode7games.com/blog
05/07/2006 (5:22 pm)
FYI, a string enclosed by single quotes:'text'
is called a tag and is handled more efficiently by the net stuff, which is why commandToClient/Server has to be a tag.
Ian
www.mode7games.com/blog
#4
Hopefully it helped =)
05/08/2006 (9:25 pm)
I didn't test that (I'm sure you know how well my untested code works ;)Hopefully it helped =)
Torque 3D Owner Jesse (Midhir) Liles
// Client side
function pickupitem(%val)
{
if (%val)
CommandToServer("pickitup", 1);
else
CommandToServer("pickitup", 0);
}
//server side
function serverCmdPickitup(%client, %x) {
%client.pickitup = %x;
}
then change all your if ($Pickitup == ?) to if (%obj.client.pickitup == ?)