Game Development Community

Character Select in Level using a GUI

by Tennyson · in Technical Issues · 06/15/2006 (4:06 pm) · 6 replies

I'm making a FPS and want the players to be able to change 'classes' (different player.cs files, Assassin.cs Berzerker.cs and Scout.cs) in game at death as it stands now when the game loads a team select GUI loads then the Character Select GUI loads you select the character and hit apply that sends a value ( 0 1 or 2, $character) to the game.cs. i renamed all the player bodies to AssassinBody, BezerkerBody and ScoutBody.

game.cs...

// ///////////////////////////////////////
// character scripts
// //////////////////////////////////////
exec("./characters/assassin.cs");
// exec("./characters/heavyweapons.cs");
exec("./characters/bezerker.cs");
// exec("./characters/medic.cs");
// exec("./characters/trooper.cs");
// exec("./characters/regenerator.cs");
// exec("./characters/sniper.cs");
exec("./characters/scout.cs");

....
function GameConnection::createPlayer(%this, %spawnPoint)
{
...

%player = new Player()
{

if($character == 0)
{
dataBlock = AssassinBody;
}
if($character == 1)
{
dataBlock = BezerkerBody;
}
if($character == 2)
{
dataBlock = ScoutBody;
}
client = %this;
};
...

//character select GUI calls this
function GameConnection::charSelect(%this, $character)
{
%this.player.kill("Suicide");
%this.spawnPlayer(); //gets a random spawn point and calls createPlayer()
}

i guess i have to load the datablocks differently?? (btw i tried a switch case instead of the ifs) oh and if i error($character); the value will change in the game.cs. i've also tried if($character == "1") in case it was sending a string instead of a int. and if i just put dataBlock = ScoutBody or the others they all load no problem.

any help would be greatly appreciated!!

About the author

Recent Threads


#1
06/15/2006 (4:31 pm)
......

if($character == 0)
   %dataBlock = AssassinBody;

else if($character == 1)

     %dataBlock = BezerkerBody;

else if($character == 2)
     %dataBlock = ScoutBody;




%player = new Player() {   datablock=%datablock; };
...

try something along these lines perhaps? i remember trying to "code" in the datablocks and it didn't like it.
#2
06/15/2006 (4:38 pm)
Thanks but i figured it out after ...


%player = new Player()
{
dataBlock = AssassinBody

client = %this;
};
MissionCleanup.add(%player);

//i put....

if($character == 0)
{
%player.dataBlock = AssassinBody;
}
if($character == 1)
{
%player.dataBlock = BezerkerBody;
}
if($character == 2)
{
%player.dataBlock = ScoutBody;
}

... and it worked, i might make a resource on this or something
#3
06/15/2006 (5:11 pm)
Just a small note-
i'd recommend using %player.setDatablock(whatever) instead of %player.datablock=whatever.
#4
06/15/2006 (7:36 pm)
Well, I would suggest a little better code. Using if in the way you do there is not very performant. Lets say that $character is 0 then you will still do all the other if statements though they are not needed. Using a switch statement makes this selection faster and also a lot cleaner to look at:
...
switch($character)
{
    case 0:
        $player.setDatablock(AssassinBody);
    case 1:
        $player.....
    case 2:
        $player.....
}
#5
06/15/2006 (8:14 pm)
Orion is correct...if you are changing the datablock outside of the original assignment within the new operator, you need to use setDataBlock() so that the appropriate changes are made throughout the %player object.
#6
06/16/2006 (1:10 pm)
Yah now that i have it changing the datablock i went back to useing a select case and i changed that to setDataBlock() as well

Thanks for all the help!!, i hope this thread helps other people with this. i'm sure character select is a common issue.

if anyone wants i'll post my gui code it's just a default gui that loads on key press, the next mission is going to be to have either a jpg or a dts viewer for each model in that screen.

i'm pretty new to Torque(about 2 months) but i'm amazed at how easy it is to pick up and the forums are great, it seems like there is a really good group of helpful ppl using this engine. the only problems i've had is making a split screen 2 player mode. however our game is due in a week so there is no time. after i get the gui looking decent i'm going to jump into bot AI YEAH!!! hehe *shudder*

btw i'm in my last term of Video Game Design and Developement at IADT in Toronto