commandToClient help
by Trevor Lift · in Torque Game Engine · 01/08/2010 (5:19 pm) · 6 replies
I have searched the forums for an answer but i am probably not using the right search terms. I am trying to make a win screen in Torque Game Engine 1.5.2. I have a win screen set up in the gui and it is executed. I have an object that the player will collect, causing the win screen to display. Here is my code so far.
i am slightly new with torque script so bare with me here. also i am sorry in advance if this question has already been asked.
i hope i provided enough info and thank everyone in advance for helping out.
//variables
$keysTotal = 2;
$keysCollected = 0;
datablock ItemData(MicroChip)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Microchip";
// Basic Item properties
shapeFile = "~/data/shapes/microchip/microchip.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
};
function MicroChip::onCollision(%this,%obj,%col)
{
echo("pick me up!!!!!!!!");
%obj.setHidden(true);
commandToClient(%client, "endGameforFun");
error("commandToClient called");
}
function endGameforFun()
{
error("endgameforfun function called");
disconnect();
Canvas.setContent(winner);
}i am slightly new with torque script so bare with me here. also i am sorry in advance if this question has already been asked.
i hope i provided enough info and thank everyone in advance for helping out.
#2
"normal string"
'tagged string'
For example:
CommandToClient(%clientConn, 'justDoIt');
You have to build the function justdoIt this way:
01/09/2010 (5:58 am)
As far as i know "commandToServer" and "commandToClient" need tagged strings for the names of the function. "normal string"
'tagged string'
For example:
CommandToClient(%clientConn, 'justDoIt');
You have to build the function justdoIt this way:
function clientCmdjustDoIt()
{
// some code
}
#3
01/09/2010 (6:06 pm)
Good catch, Thomas - I think you're right.
#4
This is the code on the server side
and this is the code i have added to the client.cs file
i am using error instead of echo for visibility in the console log when running the game.
01/10/2010 (2:51 pm)
In my first post, I was trying to run the function on the server side. Doing what Daniel told me about putting the function that needs to run on the client side, I put that in the client.cs file. here is the code as it stands now. It still does not work. Think I might have missed a simple.This is the code on the server side
datablock ItemData(MicroChip)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Microchip";
// Basic Item properties
shapeFile = "~/data/shapes/microchip/microchip.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
};
function MicroChip::onCollision(%this,%obj,%col)
{
echo("pick me up!!!!!!!!");
%obj.setHidden(true);
CommandToClient(%clientConn, 'EndFunGame');
error("talking to client");
}and this is the code i have added to the client.cs file
function clientCmdEndFunGame()
{
error("EndFunGame function called");
disconnect();
Canvas.setContent(winner);
}i am using error instead of echo for visibility in the console log when running the game.
#5
01/10/2010 (3:52 pm)
i got it working. i realized that Canvas.setContent is case sensitive. it's suppose to be canvas.setContent. thanks for all the help! :D
#6
In your case it may have just been that the script file needed to be recompiled.
01/12/2010 (1:53 pm)
Of the myriad problems that could have caused your code to fail, I can assure you the case sensitivity of Torque's identifiers is not one of them. You may unintentionally write very subtle bugs if you do not realize that Canvas, canvas and CaNvAs are interchangeable identifiers for the same object.In your case it may have just been that the script file needed to be recompiled.
Torque Owner Daniel Buckmaster
T3D Steering Committee
function endGameforFun() { error("endgameforfun function called"); disconnect(); Canvas.setContent(winner); }For a start, functions that are going to be called as client commands need to be named 'function clientCmdYourNameHere'. They also need to be executed on the client-side, rather than the server. I assume the script you posted is in server/scripts? The client doesn't execute those scripts, so it won't know about the endGameForFun function. You should place this function somewhere in the client/scripts folder, either in a new file (make sure you exec it in client/init.cs) or in one of the existing files (maybe just client.cs).