Weird Gui.cs Issue
by Jon Jorajuria · in Torque Game Engine · 01/05/2006 (8:30 am) · 3 replies
I am having a weird problem with my gui.cs files. I have two gui.cs files that do exactly the same functionality only they are for two different teams. Here is how it is supposed to work:
1. User selects a team
2. Team gui calls one of the two character selection guis.
When I comment out one of the GUIs via the init.cs file, everything works fine. When the init.cs file loads both of them only the first Gui.cs file that is loaded works properly. When both are loaded, for some reason the second Gui.cs file still looks in the first Gui.cs file's directory for the models. Here is a copy of the code, the only diference between the two is the hard coded paths and the function modelsetupgui:
function teamASetupGui::onWake(%this)
{
echo( "Model Name set ---> " @ $pref::Player::Armor );
//execute the scripts to load the dts values
%filename = "fps/data/models/characters/teamA/*.cs";
echo("filename:" @ %filename @ "\n");
$modelNum = 0;
for (%file = findFirstFile(%filename); %file !$= ""; %file = findNextFile(%filename)) {
echo("file:" @ %file @ "\n");
exec(%file);
}
//Load up the models
%filename = "fps/data/models/characters/teamA/*.dts";
echo("filename:" @ %filename @ "\n");
$modelNum = 0;
for (%file = findFirstFile(%filename); %file !$= ""; %file = findNextFile(%filename)) {
// exec(filePath(%file) @ "/player_info.cs");
//exec(%file);
//echo("file:" @ %file @ "\n");
if ( %file !$= "fps/data/models/characters/player/debris_player.dts" ) {
$modelNum++;
$modelList[$modelNum] = %file;
$modelName[$modelNum] = filebase(%file);
echo("model num " @ $modelNum @ ", model name:" @ $modelName[$modelNum]);
}
}
//Check for valid file name.. we dont want to explode
%foundnum = 0;
for ( %i = 0; %i < $modelNum; %i++ )
{
if ( $pref::Player::Armor $= $modelName[%i] ){
//Filename is valid
%foundnum = %i;
}
}
//if we dont find this model then we have a problem
//reset it to something safe
if ( %foundnum == 0 ){
echo("WARNING MODEL NAME --->" @ $pref::Player::Armor @ " NOT FOUND. Reseting to " @ $modelName[1]);
$modelCur = 1;
$pref::Player::Armor = "" @ $modelName[1];
}
if ($modelNum > 0) SP_setModel();
}
//------------------------------------------------------------------------------
function teamASetupGui::onSleep(%this)
{
}
function SP_showNextModel()
{
if ( ($modelCur) == $modelNum ) $modelCur = 1; // go back to the first model
else $modelCur = $modelCur +1; // go to the next model
$pref::Player::Armor = "" @ $modelName[$modelCur];
SP_setModel();
}
function SP_showPrevModel()
{
if ( $modelCur == 1 ) $modelCur = $modelNum; // we were at the first model so lets go to the last
else $modelCur = $modelCur -1;
$pref::Player::Armor = "" @ $modelName[$modelCur];
SP_setModel();
}
function SP_setModel()
{
echo( "Model Name set ---> " @ $pref::Player::Armor );
// Set main object
view.setObject("model_01", "fps/data/models/characters/teamA/" @ $pref::Player::Armor @ ".dts", "", 0); // set the model that should be showing
view.loadDSQ("model_01", "fps/data/models/characters/animations/player_root.dsq"); //load an animation
view.setSequence("model_01", "root", "1"); //play the animation
}
function jointeam()
{
commandtoserver('jointeam', 2, $pref::Player::Armor);
Canvas.setContent(playGui);
Canvas.popDialog(teamASetupGui);
}
Thank you in advanced for your help...I know it is a variable set at load time, but I do not understand which one. I'd like to be able to hard code the proper directories or fix the conflict..
1. User selects a team
2. Team gui calls one of the two character selection guis.
When I comment out one of the GUIs via the init.cs file, everything works fine. When the init.cs file loads both of them only the first Gui.cs file that is loaded works properly. When both are loaded, for some reason the second Gui.cs file still looks in the first Gui.cs file's directory for the models. Here is a copy of the code, the only diference between the two is the hard coded paths and the function modelsetupgui:
function teamASetupGui::onWake(%this)
{
echo( "Model Name set ---> " @ $pref::Player::Armor );
//execute the scripts to load the dts values
%filename = "fps/data/models/characters/teamA/*.cs";
echo("filename:" @ %filename @ "\n");
$modelNum = 0;
for (%file = findFirstFile(%filename); %file !$= ""; %file = findNextFile(%filename)) {
echo("file:" @ %file @ "\n");
exec(%file);
}
//Load up the models
%filename = "fps/data/models/characters/teamA/*.dts";
echo("filename:" @ %filename @ "\n");
$modelNum = 0;
for (%file = findFirstFile(%filename); %file !$= ""; %file = findNextFile(%filename)) {
// exec(filePath(%file) @ "/player_info.cs");
//exec(%file);
//echo("file:" @ %file @ "\n");
if ( %file !$= "fps/data/models/characters/player/debris_player.dts" ) {
$modelNum++;
$modelList[$modelNum] = %file;
$modelName[$modelNum] = filebase(%file);
echo("model num " @ $modelNum @ ", model name:" @ $modelName[$modelNum]);
}
}
//Check for valid file name.. we dont want to explode
%foundnum = 0;
for ( %i = 0; %i < $modelNum; %i++ )
{
if ( $pref::Player::Armor $= $modelName[%i] ){
//Filename is valid
%foundnum = %i;
}
}
//if we dont find this model then we have a problem
//reset it to something safe
if ( %foundnum == 0 ){
echo("WARNING MODEL NAME --->" @ $pref::Player::Armor @ " NOT FOUND. Reseting to " @ $modelName[1]);
$modelCur = 1;
$pref::Player::Armor = "" @ $modelName[1];
}
if ($modelNum > 0) SP_setModel();
}
//------------------------------------------------------------------------------
function teamASetupGui::onSleep(%this)
{
}
function SP_showNextModel()
{
if ( ($modelCur) == $modelNum ) $modelCur = 1; // go back to the first model
else $modelCur = $modelCur +1; // go to the next model
$pref::Player::Armor = "" @ $modelName[$modelCur];
SP_setModel();
}
function SP_showPrevModel()
{
if ( $modelCur == 1 ) $modelCur = $modelNum; // we were at the first model so lets go to the last
else $modelCur = $modelCur -1;
$pref::Player::Armor = "" @ $modelName[$modelCur];
SP_setModel();
}
function SP_setModel()
{
echo( "Model Name set ---> " @ $pref::Player::Armor );
// Set main object
view.setObject("model_01", "fps/data/models/characters/teamA/" @ $pref::Player::Armor @ ".dts", "", 0); // set the model that should be showing
view.loadDSQ("model_01", "fps/data/models/characters/animations/player_root.dsq"); //load an animation
view.setSequence("model_01", "root", "1"); //play the animation
}
function jointeam()
{
commandtoserver('jointeam', 2, $pref::Player::Armor);
Canvas.setContent(playGui);
Canvas.popDialog(teamASetupGui);
}
Thank you in advanced for your help...I know it is a variable set at load time, but I do not understand which one. I'd like to be able to hard code the proper directories or fix the conflict..
About the author
Torque Owner Kirby Webber
Sounds to me like one set of functions is overwriting the other in memory because they ahve the same names?
Worth a try. =)