Game Development Community

How do you create mulitple players that have differnt state? Tha

by Nick B. · in Torque Game Engine · 05/16/2003 (1:37 pm) · 6 replies

I am having what I think is a ghosting/networking problem. I have a bot (a subclass of Player.cc), which stores information about which waypoint to go to next. OnMissionLoad, the script initializes 4 of these bots, and they all have separate waypoints to go to. However, when the dataobject's are finished loading and the game is about to begin, the default constructor for the bot is called again (4 times, to be precise), and when the bots appear in the level, they all have the same waypoint as their goal. What is more, when one bot reaches its waypoint and starts going toward its next waypoint, all of the other bots start doing the same thing, even if they haven't yet reached their waypoint. So not only are the bots all being instantiated the same, the bots also seem to share the same state. It's got me quite irate. If you have any advice or need more information, I'll be here. Thanks a million,
Cheers,
Joe

About the author

Recent Threads


#1
05/19/2003 (12:38 am)
Nick sounds like you are placing your bot specific info in the datablock,

this is a no-no as the datablock is static for all instances.
you need to store your info with the instance.
#2
05/19/2003 (7:06 am)
Hey Badguy, thanks for the response.

I am pretty sure that I am not storing player specific info in the datablock, but here's the initialization code, just to make sure. Maybe I misunderstood something about how datablock's work.

The C++ code:
// handles the setup after the datablock code is complete
void BehaviorCommuter::init(const char* name) {
// set some basic characteristics
mMoveSpeed = 1;
setEnergyLevel(60);
setShapeName(name);
this->waypoints = AILevelLoader::waypoints;
this->loop = AILevelLoader::loop;
AILevelLoader::advanceWaypoint();

// find and set the spawn point
setTransform(AILevelLoader::spawnLocation);
}




The Script code:
function AILevelLoader::spawnBehaviorCommuter(%name)
{
// An example function which creates a new AIPlayer object
// using the the example player datablock.
echo("!!!!!!SPAWNING BehaviorCommuter");
%player = new BehaviorCommuter()
{
dataBlock = LightMaleHumanArmor;
aiPlayer = true;
};

// handle book keeping
MissionCleanup.add(%player);

// Player setup
%player.init(%name);
%player.incInventory(Rifle, 1);
%player.incInventory(RifleAmmo, RifleAmmo.maxInventory);
%player.use(Rifle);
return %player;
}



Thanks again for the help,
Joe
#3
05/19/2003 (3:53 pm)
ok Joe :)
this looks ok, so Maybe then it must be your code that maintains the players and tells them when to change waypoint.

what does this do:
AILevelLoader::advanceWaypoint();?

i'll assume ..::waypoints is a list of points or something of the sort.. and ..::loop is a flag of somekind.


so this narrows it doing to being within your bot handling code, on destination get next point stuff... ?
Quote:and when the bots appear in the level, they all have the same waypoint as their goal.
i'll assume that the desired effect is to have them not have the goal as the point but the first point in the list?

lets clarify:
does one bot in the mission do the proper routines?

and a Question:
where does BehaviorCommuter inherit from?
and when you add more than one it mess's up as they all follow one's code?
#4
05/19/2003 (4:37 pm)
"lets clarify" -- Good idea.

0) "what does this do: AILevelLoader::advanceWaypoint();?
i'll assume ..::waypoints is a list of points or something of the sort.. and ..::loop is a flag of somekind."

The class AiLevelLoader is used for initialization that stores the waypoints as a static variable. When advanceWaypoint() is called, the first item on the waypoint list removed and then is added to the end of the waypoint list. You're right, loop is just a flag.


1) "does one bot in the mission do the proper routines?"

Yes. With just one bot you get:

bot1: A->B->C->D->A (goes to waypoint A, then B, then C, then D, then A...)


With 4 bots, you should get:
bot1: A->B->C->D->A

bot2: B->C->D->A->B

bot3: C->D->A->B->C

bot4: D->A->B->C->D



2) "Where does BehaviorCommuter inherit from?"
I have BehaviorCommuter inheriting from Player.

3) "when you add more than one it mess's up as they all follow one's code?"

Yes. With 4 bots you get
bot1: A->B->C->D->A
bot2: A->B->C->D->A
bot3: A->B->C->D->A
bot4: A->B->C->D->A

Once more, thanks a million!
-Joe
#5
05/19/2003 (4:44 pm)
Quote:3) "when you add more than one it mess's up as they all follow one's code?"

Yes. With 4 bots you get
bot1: A->B->C->D->A
bot2: A->B->C->D->A
bot3: A->B->C->D->A
bot4: A->B->C->D->A

then you are storing the info in the datablock which is STATIC for all instances!

you have to either have a datablock for each waypoint path or figure out how to load the different waypoint paths into each INSTANCE
#6
05/20/2003 (4:41 pm)
So I take it Jarrod Pointed out this issue and you have resolved it?

so its the actual List that is static ..
and providing the same info for each bot