timer of shot help

Talk about making games.

timer of shot help

Postby Morpheas » Wed Feb 22, 2012 6:47 pm

CreateActor("shot", "shot0001", "cannon", "(none)", 0, 0, false),
shot.angle=animpos=direction(x,y,crosshair.x,crosshair.y),
shot.directional_velocity=3;
this in key down (space) NON repeatable event.
now my problem is:
1) how to put it a timer so it can refire after lets say 1sec. :) i dont know how:P im a beginner in game editor:)
2) is it possible the actor to begin transparent and after lets say 1 sec(timer)make it visible?
any help will be appreciated.
Last edited by Morpheas on Thu Feb 23, 2012 5:34 pm, edited 2 times in total.
Morpheas
 
Posts: 17
Joined: Mon Feb 20, 2012 12:58 pm
Score: 1 Give a positive score

Re: timer of shot help

Postby skydereign » Thu Feb 23, 2012 1:14 am

Assuming the cannon has no other keydown events you can use EventDisable to disable the key events, and create a timer. In the timer event it can enable the key event again. This would bypass the need to use a variable, but because it is good practice I'll explain the other way.

Create a variable to determine if you can shoot or not. When it equals 0 it means you can shoot. Any other value means you can't (namely if it is 1). When you fire, you set it equal to 1, and create a 1 second timer. After the timer you set it back to 0 that way you can shoot again.
Code: Select all
if(cannon_state == 0) // you can fire
{
    // put the CreateActor and angle code here
    cannon_state=1; // disables the cannon until the timer event
    CreateTimer("Event Actor", "reset", 1000);
}

Notice that if cannon_state is not equal to 0, gE will ignore the CreateActor function, and so no bullet will be fired. It also creates a timer event which should have the following code (make sure the timer event does not repeat).
cannon -> Timer (reset) -> Script Editor
Code: Select all
cannon_state=0; // cannon can fire again


As for your second question you can also use a timer event for this. You want the actor to be invisible when it is created, so you can sets its transp to 1 (transparency is max at 1).
actor -> Create Actor -> Script Editor
Code: Select all
transp=1; // set to transparent
CreateTimer("Event Actor", "visible", 1000);

actor -> Timer (visible) -> Script Editor
Code: Select all
transp=0; // make the actor visible
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: timer of shot help

Postby Morpheas » Thu Feb 23, 2012 9:31 am

all the above worked (im a believer )u saved me from days of brain burning:P
now i ll tamper with the code thx :) and now i have a better understanding:)
Morpheas
 
Posts: 17
Joined: Mon Feb 20, 2012 12:58 pm
Score: 1 Give a positive score

Re: timer of shot help

Postby Morpheas » Thu Feb 23, 2012 5:39 pm

mmm. 1 more problem...
the first time i press space key if i leave it and press it fast again it might refire 1 extra shot.
if i keep it pressed the time works perfect.what is the problem?
Morpheas
 
Posts: 17
Joined: Mon Feb 20, 2012 12:58 pm
Score: 1 Give a positive score

Re: timer of shot help

Postby skydereign » Thu Feb 23, 2012 9:17 pm

That shouldn't happen, unless something is causing the timer to reset it. Try putting a text actor with the following code.
text_display -> Draw Actor -> Script Editor
Code: Select all
textNumber = cannon_state;

Only when that shows a 0 should you be able to fire. You might also try increasing the timer length as a way of comparing.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: timer of shot help

Postby Morpheas » Fri Feb 24, 2012 3:31 pm

it must conflict because in the key down space actor cannon i have
CreateTimer("Event Actor", "reset", 2000);
and then when i tried to add timer it told me there is no timer so i created a timer named reset with 1000 ms and then deleted the timer.....
do u know a way to delete the timer reset permanently from the GUI
or how to edit an existing timer
or what to do?
Morpheas
 
Posts: 17
Joined: Mon Feb 20, 2012 12:58 pm
Score: 1 Give a positive score

Re: timer of shot help

Postby skydereign » Fri Feb 24, 2012 7:32 pm

To delete a timer you have to remove all references to it. That means remove all CreateTimer calls that call it, and all timer events bound to it. gE takes care of it from there (I'd prefer if we could delete timers and edit them manually but that's just how it goes). You can't edit timers though you can change the time they take. Below uses the same timer, but different times.
Code: Select all
ChangeTimer("Event Actor", "reset", 1000); // this would create a 1 second timer
ChangeTimer("Event Actor", "reset", 5000); // this would create a 5 second timer
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest