Multiple Status Bars
by Derek Stanton · in Torque Game Engine · 03/17/2009 (10:15 pm) · 0 replies
EDIT: Took a few hours to do (I know, sad), but it feels good to do stuff by myself :) I had to do a lot of research
I have a health bar that shows up when you select another player, "TargetStatusbar", which is made in PlayGui. The problem is the script doesn't create a new bar every time you select a new person, it just sets the TargetStatusbar visible with an updated health and name.
I am wondering how to create multiple instances of the gui upon selecting a new target. So it creates a health bar for everyone's health bar you don't have open.
One option I am thinking is to have 9 statusbars defined in playgui, and have the onselection method cycle through them. Any help on this?
I know it would go something like this, but I really don't know how to do it properly.
Thanks
Derek
$barCnt = 1;
$list = new SimSet();
function GameConnection::onObjectSelected(%this, %obj)
{
%i = 0;
if (%obj.selectron == 0 && %obj != %this.getControlObject())
{
%selectron = startSelectron(%obj, $afxCurrentSelectronStyle);
if (%selectron != 0)
%selectron.addConstraint(%obj, "selected");
%obj.selectron = %selectron;
}
if ($barCnt > 1)
{
while (%i < $list.getCount())
{
if ($list.getObject(%i).getShapeName() $= %obj.getShapeName())
{
return;
}
else
{
%i++;
}
}
$list.add(%obj);
%label = "TargetStatusbarLabel" @ $barCnt;
%bar = "TargetStatusbar" @ $barCnt;
%health = "TargetHealthStatusBar" @ $barCnt;
%energy = "TargetEnergyStatusBar" @ $barCnt;
%label.setName(%obj.getShapeName());
%bar.visible = true;
%health.setShape(%obj);
%energy.setShape(%obj);
$barCnt = $barCnt++;
if ($barCnt == 11)
$barCnt = 1;
return;
}
else
{
$list.add(%obj);
echo ( "FIRST" @ ".." @$list.getObject(0).getShapeName() @ ".." @ %obj.getShapeName());
%label = "TargetStatusbarLabel" @ $barCnt;
%bar = "TargetStatusbar" @ $barCnt;
%health = "TargetHealthStatusBar" @ $barCnt;
%energy = "TargetEnergyStatusBar" @ $barCnt;
%label.setName(%obj.getShapeName());
%bar.visible = true;
%health.setShape(%obj);
%energy.setShape(%obj);
$barCnt = $barCnt++;
}
}I have a health bar that shows up when you select another player, "TargetStatusbar", which is made in PlayGui. The problem is the script doesn't create a new bar every time you select a new person, it just sets the TargetStatusbar visible with an updated health and name.
I am wondering how to create multiple instances of the gui upon selecting a new target. So it creates a health bar for everyone's health bar you don't have open.
One option I am thinking is to have 9 statusbars defined in playgui, and have the onselection method cycle through them. Any help on this?
I know it would go something like this, but I really don't know how to do it properly.
function GameConnection::onObjectSelected(%this, %obj)
{
if TargetStatusbar %i .title != %obj.getShapeName()
{
%i = %i++;
TargetStatusbarLabel %i .setName(%obj.getShapeName());
TargetStatusbar %i .visible = true;
TargetHealthStatusBar %i .setShape(%obj);
TargetEnergyStatusBar %i .setShape(%obj);
}
}Thanks
Derek
About the author