Timer end on script, can be done?

Talk about making games.

Timer end on script, can be done?

Postby FERdeBOER » Mon Jul 26, 2010 5:10 pm

My question of the day is this: is it possible to make a script including the end of a timer?

I mean: I would like to create a script which includes an action when the timer ends.
I know there's the TIMER option, but I wonder if It can be putted all in the same "package".

Something like this:
Code: Select all
if(landing==1)
{
   CreateTimer("Event Actor", "takeoff", 2000);
   and here some kind of if(takeofftimer==0)
                         {
                             CreateActor....
                         }
}


Is there a way for doing this?

Thank you very much.
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score

Re: Timer end on script, can be done?

Postby Bee-Ant » Mon Jul 26, 2010 5:42 pm

FERdeBOER wrote:is it possible to make a script including the end of a timer?

Possible.


For instance you want to check your character's type by timer.

Player -> CreateActor -> ScriptEditor:
Code: Select all
type=rand(100);
CreateTimer("Event Actor","CheckType",100);


Timer -> "CheckType" -> ScriptEditor:
Code: Select all
if(type==0)
{
   //do something 1
}
if(type==1)
{
    //do something 2
}
//etc
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Timer end on script, can be done?

Postby FERdeBOER » Mon Jul 26, 2010 7:35 pm

Thank you for your fast reply.
Question: why do you randomize with rand(100)?
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score

Re: Timer end on script, can be done?

Postby FERdeBOER » Mon Jul 26, 2010 10:35 pm

Now I look twice your code... it implies using Timer -> "CheckType" -> ScriptEditor
I'm asking if it's possible to avoid doing this, including the action when the timer ends on the same script where it has been created.
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score

Re: Timer end on script, can be done?

Postby Bee-Ant » Tue Jul 27, 2010 4:32 am

FERdeBOER wrote:Thank you for your fast reply.
Question: why do you randomize with rand(100)?

It's just an example...you don't need to use ran() anyway...

FERdeBOER wrote:Now I look twice your code... it implies using Timer -> "CheckType" -> ScriptEditor
I'm asking if it's possible to avoid doing this, including the action when the timer ends on the same script where it has been created.

No...
All the codes in one section, will be executed at one time.
So if you want to suspend it by Timers, you have to use Timer event. CAN'T avoid it :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Timer end on script, can be done?

Postby Bee-Ant » Tue Jul 27, 2010 4:38 am

EXCEPT, you want to suspend it by variables, you don't need Timer usage...
For example, you want to make your Player's health to be increased at certain timing, so...

Player -> Draw Actor -> Script Editor :
Code: Select all
int count;
count+=1;
if(count>=100)
{
    health+=10;
    count=0; //reset the count
}

In that code, your player's health will be increased only if count equal to 100.
And remember, this can only be done in Draw Actor, you can't use this method on any other event...
Hope helps :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Timer end on script, can be done?

Postby FERdeBOER » Tue Jul 27, 2010 11:11 am

Thank you very much!

Ok, so I must use Timer... :mrgreen:
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest