CommandToClient
by Skylar Kelty · in Torque Game Engine · 06/27/2006 (9:55 am) · 27 replies
Hi,
Im trying to implement a campaign mode in DawnOfMen but im stuck trying to use commandtoclient
The system goes:
get progress
startmission based on progress
on exit trigger entered, commandtoclient
wait for user to press continue
start next mission
Heres the client command:
And heres my commandtoclient
Whats wrong with that?
Thanks in advance
Im trying to implement a campaign mode in DawnOfMen but im stuck trying to use commandtoclient
The system goes:
get progress
startmission based on progress
on exit trigger entered, commandtoclient
wait for user to press continue
start next mission
Heres the client command:
function clientCmdContinuecmp()
{
disconnect();
canvas.setcontent(CampaignGUI);
oncampaignmissionend();
}And heres my commandtoclient
commandtoclient(%client,"Continuecmp");
Whats wrong with that?
Thanks in advance
About the author
#2
06/27/2006 (10:24 am)
Thanks Andrew, it was the tags
#3
Edit: Basically I want to end the game from a function on the server
06/27/2006 (10:36 am)
Can I just use continuecmp(); in the server code even though continuecmp is on the client?Edit: Basically I want to end the game from a function on the server
#4
-Andrew
06/27/2006 (10:48 am)
Well, as far as I understand your question and your scenario - one instance of the game is both the client and server, and while processing something in the "server" side method, you decide to call continuecmp for the client, right? If that's the scenario then the answer is, I believe, yes. Just call continuecmp() without the overhead of commandToClient.-Andrew
#5
The server side stuff
06/27/2006 (10:59 am)
datablock TriggerData(exitTrigger)
{
tickPeriodMS = 500;
};
function exitTrigger::onEnterTrigger(%data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
if(!%client)
{
return;
}
if(%checkname $= "exit")
{
continuecmp();
}
}The server side stuff
#6
*** ENDING MISSION
CDROP: 1831 IPX:00000000:00000000E416:293
Then crash
06/27/2006 (11:04 am)
The game crashes when I go through the triggerfunction continuecmp()
{
disconnect();
canvas.setcontent(CampaignGUI);
//oncampaignmissionend();
}Client side*** ENDING MISSION
CDROP: 1831 IPX:00000000:00000000E416:293
Then crash
#7
Sorry I've reached the end of my usefulness so soon :)
-Andrew
06/27/2006 (11:12 am)
Phhhbbbbbtt! I've got code that does pretty much the same thing using TGB.. that's really where I spend most of my time though so I may be missing something huge. Anyone else got any ideas?? :)Sorry I've reached the end of my usefulness so soon :)
-Andrew
#8
/me shoots in the dark
-Andrew
06/27/2006 (11:14 am)
Um, do you really need to disconnect right then? maybe just setContent and see if that works../me shoots in the dark
-Andrew
#9
06/27/2006 (11:14 am)
You're probably ticking too many times and the game crashes when it tries to disconnect you from a gameConnection that no longer exists. Try putting a variable or global in there that checks if the function has been called once, and if it is true, do not call the function again.
#10
06/27/2006 (11:18 am)
Thankyou both, will try what Stefan said
#12
Anyway, that'll give you a syntax error so definatly do not do that.
Just put a global in there, set it to true when you disconnect.
Like:
06/27/2006 (11:55 am)
Dude, what's tickPeriodMS - is it even exposed to script?Anyway, that'll give you a syntax error so definatly do not do that.
Just put a global in there, set it to true when you disconnect.
Like:
if ($bool != true)
{
// disconnect
$bool = true;
}
#13
06/27/2006 (12:00 pm)
TickPeriodMS is used in almost all triggers
#14
Edit: I used the cycleexec's and told them to setcanvas to the campaign gui, thanks for all the help :)
BTW in case you didnt realize it works (kinda) now, few major bugs but I got done what I wanted done until Beta when all the bugs will be ironed out, which is something im not looking forward to doing :(
06/27/2006 (12:10 pm)
No the problem is coming when I call to the client if I use server functions like cycleexec its fineEdit: I used the cycleexec's and told them to setcanvas to the campaign gui, thanks for all the help :)
BTW in case you didnt realize it works (kinda) now, few major bugs but I got done what I wanted done until Beta when all the bugs will be ironed out, which is something im not looking forward to doing :(
#15
I'm not sure you're understanding how to properly code this. Look at your 4th post with code. It's all okay until you step into the ContinueCmp function, in which there are code that never should run on a server - so that might crash.
If I understand you correctly, you also tried with a commandToClient call, but again.. what have you done to trace the problem? Try to comment everything in your function and then uncomment line by line until you can trace your crash to a single line or function.
I think that's common practice in TS if anything.
You shouldn't be getting memory leaks if you do it correctly.
Edit: You'll have to be more clear and explain what "them" and "calling client" means. You do not call the client, you send a packet to it where you ask it to run a function. How far does it go? Is the clientCmd function never run, or does the packet never arrive? Etc. Details.
06/27/2006 (12:32 pm)
Quote:
No the problem is coming when I call to the client if I use server functions like cycleexec its fine
I'm not sure you're understanding how to properly code this. Look at your 4th post with code. It's all okay until you step into the ContinueCmp function, in which there are code that never should run on a server - so that might crash.
If I understand you correctly, you also tried with a commandToClient call, but again.. what have you done to trace the problem? Try to comment everything in your function and then uncomment line by line until you can trace your crash to a single line or function.
I think that's common practice in TS if anything.
You shouldn't be getting memory leaks if you do it correctly.
Edit: You'll have to be more clear and explain what "them" and "calling client" means. You do not call the client, you send a packet to it where you ask it to run a function. How far does it go? Is the clientCmd function never run, or does the packet never arrive? Etc. Details.
#16
06/27/2006 (12:34 pm)
Use a disconnectCleanup() call instead of disconnect(). Worked for me in TSE.
#17
When you call disconnect() you also call disconnectedCleanup(). So that won't do any difference unless the poster changed the disconnect() function from stock.
06/27/2006 (12:35 pm)
@Martin:When you call disconnect() you also call disconnectedCleanup(). So that won't do any difference unless the poster changed the disconnect() function from stock.
function disconnect()
{
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();
disconnectedCleanup();
// Call destroyServer in case we're hosting
destroyServer();
}
#18
I used echo's to trace the problem
All the necessary functions were getting called but when I called disconnect(); the game crashed. Now I am using the cycleexec's to end the game and that works unless I try tostart another so I am giving up for today, tomorrow Ill have another go.
My code:
server/scripts/campaignmode.cs
in server/scripts/game.cs
06/27/2006 (12:51 pm)
Okay, Ill try to explain.I used echo's to trace the problem
All the necessary functions were getting called but when I called disconnect(); the game crashed. Now I am using the cycleexec's to end the game and that works unless I try tostart another so I am giving up for today, tomorrow Ill have another go.
My code:
server/scripts/campaignmode.cs
datablock TriggerData(exitTrigger)
{
tickPeriodMS = 500;
};
function exitTrigger::onEnterTrigger(%data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
if(!%client)
{
echo("not a client!");
return;
}
echo("Teleport client:" SPC %client);
if(%checkname $= "exit")
{
%target = cycleGame();
$teleSched = schedule(0000,0,"goScotty",%client,%target);
%client.player.setCloaked(true);
}
}in server/scripts/game.cs
function cycleGame()
{
// This is setup as a schedule so that this function can be called
// directly from object callbacks. Object callbacks have to be
// carefull about invoking server functions that could cause
// their object to be deleted.
if (!$Game::Cycling) {
$Game::Cycling = true;
$Game::Schedule = schedule(0, 0, "onCycleExec");
}
$Game::TeamScores[1] = 0;
$Game::TeamScores[2] = 0;
$Game::Teamkings[1] = 0;
$Game::Teamkings[2] = 0;
}
function onCycleExec()
{
// End the current game and start another one, we'll pause for a little
// so the end game victory screen can be examined by the clients.
endGame();
$Game::Schedule = schedule($Game::EndGamePause * 1000, 0, "onCyclePauseEnd");
}
function onCyclePauseEnd()
{
$Game::Cycling = false;
canvas.setcontent(CampaignGUI);
}
#19
You're basically asking the server to setContent, and a server does not have a canvas to begin with.
Also:
cycleGame does not return a value, so the line above doesn't make sense.
06/27/2006 (12:54 pm)
The question is still why you are executing client-side code on the server.You're basically asking the server to setContent, and a server does not have a canvas to begin with.
Also:
%target = cycleGame();
cycleGame does not return a value, so the line above doesn't make sense.
#20
06/27/2006 (12:56 pm)
It works though
Torque Owner Andrew Douglas
this should work (case sensistivity I think can also screw you up)
commandToClient(%client, 'continuecmp');
note the tagged string and the lower case c in continue.
-Andrew