Game Development Community

Scripting - Trigger based server switching

by Carsten Tusk · in Torque Game Engine · 03/27/2004 (4:01 pm) · 5 replies

I am trying to implement some basic trigger based server switching based on one of the resources regarding that topic.

My problem is that for some reason it seems to crash the engine when initiated from the trigger, however when initiated manually it works just peachy.

Any help as to why this might be happening is appreciated, I can't seem to figure out the reason.

Here are the code snippets:

Client
function connect(%adr) {
      echo("Connect called with: '" @ %adr @ "'");
      %conn = new GameConnection(ServerConnection);
      %conn.setConnectArgs($pref::Player::Name);
      %conn.setJoinPassword($Client::Password);
      %conn.connect(%adr);
}

function clientCmdConnectServerPortal(%a1)
{
    %adr = detag(%a1);
    echo("Received connect command from server: '" @ %adr @ "'");
    if ( %adr !$= "" ) {
       disconnect();
       connect( %adr );
    } else {
       echo("Error, empty address in ConnectServerPortal");
    }
}

function s1() {
      disconnect();
      connect("IP:192.168.10.8:28000");
}

function s2() {
      disconnect();
      connect("IP:192.168.10.8:29000");
}

Server
datablock TriggerData(ServerPortalTrigger)
{
    tickPeriodMS = 100;
};

function ServerPortalTrigger::onEnterTrigger(%data, %obj, %colObj)
{
    echo ("Entered ServerPortal Trigger: " SPC %obj.getName() );
    %target = detag( %obj.destination );
    %client = %colObj.client;
    if (%client) {
       echo ("Calling client with target = '" @ %target @ "'");
       commandToClient(%client, 'ConnectServerPortal', %target );
    } else {
        echo ("Not a client");
    }
}

function ServerPortalTrigger::onLeaveTrigger(%data, %obj, %colObj)
{
    echo ("Left ServerPortal Trigger");
}

Trigger defined in mission file:
new Trigger(Trigger1) {
      position = "113.743 -281.072 33.7";
      rotation = "0 0 1 37.2422";
      scale = "3 3 3";
      dataBlock = "ServerPortalTrigger";
      polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         destination = "IP:192.168.10.8:29000";
         locked = "false";
   };

The problem occurs when the switch is initiated by the trigger, switching servers using the two functions s1() and s2() from the console works fine. The trigger based switch crashes the client.

Thanks for any hints regarding this,
Carsten

#1
03/27/2004 (4:34 pm)
Okay, this is just a guess on my part, but you could try taking all the code within onEnterTrigger() and place it in a separate function. Then within onEnterTrigger() use schedule() to make an immediate call to this new function.
#2
03/27/2004 (5:01 pm)
I got it to work now, the problem seemed to be the immediate disconnect upon receiving the command, if I schedule the disconnect/connect combo on the client with a 5000ms delay it works.

Thanks for the pointer into the right direction Kevin :)
#3
03/28/2004 (9:30 pm)
How long is 5000ms? (just trying to get the idea base for the timing) would 1s be 1000ms?
#4
03/28/2004 (10:07 pm)
Yes, you are correct. 5000ms == 5 sec.
#5
03/29/2004 (4:27 pm)
I had this problem awhile ago, here is some more information I believe will help understand why this is happening.

www.garagegames.com/mg/forums/result.thread.php?qt=4540