PDA

View Full Version : Actor's LifeSpan


Brood_of_Evil
4th Nov 2001, 09:37 PM
Hi, I have a question and I would appreciate it if any one of you can help me with this. Anyways, my question is:

Is there a way to track the remaining time an actor has after it has been spawned. In my case this is a rocket, a sub class of a RocketMk2. What I want to do is, find a way to track it's remaining time in the world after it's spawned, and to make things more realistic, call it's "Explode" function about a second before it's expiration, instead of the rocked dissapearing all of the sudden.

Is the LifeSpan variable used only to set the...well, life span of the actor, or does it also keeps track of it? Or is there some function that returns this value?

Wormbo
5th Nov 2001, 12:01 AM
The LifeSpan is the time the actor still has left. It keeps track of how much time is left. After the LifeSpan reaches 0 the Expired() function is called and the actor gets destroyed.

Brood_of_Evil
5th Nov 2001, 12:52 AM
So if I write:

Timer()
{
//some code here

if(MyActor.LifeSpan == 1)
SomeFunction();
}

Will it execute the function when one second is left before it expires?

A LifeSpan of 1.0 is a second right?

Euphoric Beaver
5th Nov 2001, 04:15 AM
Couldn't you spawn an explosion and hurt radius in the Expired() function?

EasyRaider
5th Nov 2001, 11:47 AM
Originally posted by Brood_of_Evil
So if I write:

Timer()
{
//some code here

if(MyActor.LifeSpan == 1)
SomeFunction();
}

Will it execute the function when one second is left before it expires?

A LifeSpan of 1.0 is a second right?

That code won't work. SomeFunction() will only be called if LifeSpan is exactly equal to 1, which is most likely not the case. Generally, the == operator should be avoided when dealing with floats.

Yes, LifeSpan is measured in seconds.

[edit]
And yes, I believe you should use Expired().

Papapishu
6th Nov 2001, 06:15 AM
Why don't you write:


SetTimer(Lifespan-0.5,True);

Timer()
{
Explode();
}

Or something, (dunno if Timer() is taken...)

Euphoric Beaver
7th Nov 2001, 11:36 AM
If I didn't want to use the Tick or Timer then how would I overload the Expired() function?

I looked through the classes and only found Expired as an event.
BTW what are the Events for?

Brood_of_Evil
7th Nov 2001, 09:31 PM
Thanks, well I used the expired function, you can overwrite is as any normal function, and set the code inside,

Papapishu
8th Nov 2001, 12:26 PM
event means it is called by the game when something happens, but you can call it yourself ofcourse...