Page 1 of 1

timer of shot help

PostPosted: Wed Feb 22, 2012 6:47 pm
by Morpheas
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.

Re: timer of shot help

PostPosted: Thu Feb 23, 2012 1:14 am
by skydereign
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

Re: timer of shot help

PostPosted: Thu Feb 23, 2012 9:31 am
by Morpheas
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:)

Re: timer of shot help

PostPosted: Thu Feb 23, 2012 5:39 pm
by Morpheas
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?

Re: timer of shot help

PostPosted: Thu Feb 23, 2012 9:17 pm
by skydereign
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.

Re: timer of shot help

PostPosted: Fri Feb 24, 2012 3:31 pm
by Morpheas
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?

Re: timer of shot help

PostPosted: Fri Feb 24, 2012 7:32 pm
by skydereign
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