Game Development Community

why it doesn't work?

by Anonymous · in General Discussion · 06/23/2011 (2:17 pm) · 3 replies

datablock TriggerData(DefaultTrigger){

tickPeriodMS = 100;
};

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj){

disconnect();
createServer("SinglePlayer","levels/Empty Terrain.mis");
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs("Player");
%conn.setJoinPassword("None");
%conn.connectLocal();
}

it doesn't work,just crash my computer.

About the author

better game,better life


#1
06/23/2011 (4:06 pm)
Schedule/call a missionLoad() instead of disconnecting and restarting the server which trashes everything.
function ChangeLevelTrigger::onEnterTrigger(%this, %trigger, %obj)
{
    %client = %obj.client;
    if (!%client)
    {
        // We do not want NPC's or other AIplayers walking into our trigger and
        // seting off the ChangeLevelTrigger.
        return;
    }

    // Change "YOURLEVEL.mis" to the name of your level!
    %levelName = "YOURLEVEL.mis";

    echo("\c4Transferring client: "@ %client @" to "@ %levelName);
    schedule(0, 0, loadMission, "levels/"@ %levelName, false);
}

#2
06/23/2011 (5:19 pm)
it doesnt work because disconnect() deletes all objects and datablocks.

so the trigger calls a function which tries to delete the trigger which called the function.

this is why you should use schedule() instead.
#3
06/23/2011 (9:56 pm)
I get it, and it works,thank you ,buddy