Script problem
by Martyn · in Torque Game Builder · 01/21/2009 (7:25 pm) · 5 replies
Hi,
I am posting this script as I am having a little trouble getting it to work - Im sure I am on the right path.....
I have an enemy which has a health bar mounted to it, the plan is when it gets hit by a fireball, this health bar image is exchange for another image which shows it has lost some life, this is in a cs that is set to the health bars class within level builder
This first script is called when the apprentice enemy is hit by a fire ball
function EnemyApprentice::hitByFireball(%this)
{
%this.life = %this.life - 25;
if(%this.life == 25)
{
%this.ApprenticeHealthBar();
}
if(%this.life == 0)
{
%this.SpawnApprentice();
}
}
As you can see from one of the if statements, when life is 25 it should load the ApprenticeHealthBar function below;
function ApprenticeHealthBar::ApprenticeHealth(%this)
{
%this.setImageMap(healthbar2ImageMap);
%this.setSize(7.00, 2.00);
%this.setPositionX(65.660);
%this.setPositionY(-17.169);
}
The above function changes the image of the health bar.
Am i on the correct path??
Sorry if im not lol
Thanks for any support
Martyn
I am posting this script as I am having a little trouble getting it to work - Im sure I am on the right path.....
I have an enemy which has a health bar mounted to it, the plan is when it gets hit by a fireball, this health bar image is exchange for another image which shows it has lost some life, this is in a cs that is set to the health bars class within level builder
This first script is called when the apprentice enemy is hit by a fire ball
function EnemyApprentice::hitByFireball(%this)
{
%this.life = %this.life - 25;
if(%this.life == 25)
{
%this.ApprenticeHealthBar();
}
if(%this.life == 0)
{
%this.SpawnApprentice();
}
}
As you can see from one of the if statements, when life is 25 it should load the ApprenticeHealthBar function below;
function ApprenticeHealthBar::ApprenticeHealth(%this)
{
%this.setImageMap(healthbar2ImageMap);
%this.setSize(7.00, 2.00);
%this.setPositionX(65.660);
%this.setPositionY(-17.169);
}
The above function changes the image of the health bar.
Am i on the correct path??
Sorry if im not lol
Thanks for any support
Martyn
About the author
I have been interested in game development for around 10 years, it has always remained a hobby. I am now looking to develop my skills and maybe progress it from a hobby into a 2nd income.
#2
function ApprenticeHealthBar::ApprenticeHealth(%this)
ApprenticeHealthBar is the class that the function ApprenticeHealth is associated with.
Problem with above code as well is that in the scope of the function shown, %this refers to the EnemyApprentice class, not the ApprenticeHealthBar class.
01/21/2009 (8:43 pm)
The function you want to call is not "ApprenticeHealthBar".function ApprenticeHealthBar::ApprenticeHealth(%this)
ApprenticeHealthBar is the class that the function ApprenticeHealth is associated with.
function EnemyApprentice::hitByFireball(%this)
{
%this.life = %this.life - 25;
if(%this.life == 25)
{
%this.ApprenticeHealthBar();
}
if(%this.life == 0)
{
%this.SpawnApprentice();
}
}Problem with above code as well is that in the scope of the function shown, %this refers to the EnemyApprentice class, not the ApprenticeHealthBar class.
#3
01/22/2009 (2:30 pm)
Thanks :) - Still working on it :) lol
#4
01/23/2009 (3:34 am)
In the health bar onupdate behavior function add something like this:function HealthBarBehavior::onUpdate(%this)
{
if(%this.owner.life < %this.lastLife)
{
%this.changeBar();
%this.lastLife = %this.owner.Life;
}
}
#5
01/23/2009 (3:48 am)
thanks - ill look into that :)
Torque 3D Owner Aun Taraseina
in the EnemyApprentice script class will look up for a function name
EnemyApprentice::ApprenticeHealthBar(%this){}not