[SOLVED]How do I use Timers for firing?

Get help using Construct 2

Post » Wed Aug 19, 2015 10:06 am

Hi guys,

I would like to say so far the community here has been really helpful and patient with peeps like me who have zero programming knowledge in creating games. I'm currently hard at work in creating my very first game and am really excited to see it starting to come shape.

Alas i have encountered with another problem, hope someone here can help me.

Under the system events there's "Compare Time" and "Every X seconds" but those 2 doesn't let me do what i want.

My sprite is currently firing this way but it goes on and on.

Image

I need it to stop firing after X seconds, i have downloaded rexrainbow's timer plugins but i can't seem to make it work.
Last edited by HuaHero on Thu Aug 20, 2015 7:22 am, edited 1 time in total.
B
11
S
2
Posts: 61
Reputation: 704

Post » Wed Aug 19, 2015 10:30 am

Hello,

"Every X seconds" doesn't work per instance, so if you want several objects of the same type or family firing, only one will.
You can add an instance variable (named "timer" for example) and at every tick (or every x seconds), for each object, add dt (in system expression) to the timer. In the same time you check if the timer is higher than a value, and if it is, you can fire.

- Add a "timer" instance variable for your object.
- Every tick => for each object => add dt to object instance variable timer
- If timer is higher than value : can shoot.

I hope it's clear enough. Sorry I don't know the Rexrainbow's timer plugin.
B
14
S
4
Posts: 112
Reputation: 1,287

Post » Wed Aug 19, 2015 11:47 am

There is a built in Timer behaviour. Just set it to trigger after X second and have it turn off an instance variable. Check that variable to see if you should fire or not.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Wed Aug 19, 2015 12:36 pm

Thanks @Nabu0001 and @Blackhornet for trying to help but sorry i have tried but i can't seem to get it work.

Below is the attached screenshot

Image

What i have so far now in the events is having the sprite fly into the screen then starts firing the swirl of bullets both events works separately, the problem right now is after the sprite comes into the playing field, it just stays there and doesn't fire at all.

I need something to link both events together so that the sprite flies into the screen > starts firing the swirling bullets.

I wish i could attach the capx file but i have quite a bit of custom plugins and behaviors and i think quite a number of peeps won't be able to open my capx.
B
11
S
2
Posts: 61
Reputation: 704

Post » Wed Aug 19, 2015 1:12 pm

Well every tick that time = 40 seconds it will fire..
I'm pretty sure that is only 1 tick..

You could solve this by creating a sprite and giving it timer behaviour..

Give enemy3 a boolean variable and toggle the variable on timer
If enemy3 is boolean fire, if not don't fire bullets..
If you set the timer on timer you can set the wanted time for the spraying..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 19, 2015 1:15 pm

http://www.blackhornettechnologies.com/ ... Timer.capx

I use LiteTween, but you should get it if you don't already have it. The idea is similar.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Wed Aug 19, 2015 2:12 pm

Aight, here's something simple that should do it?

1. Give Enemy3 an instance variable; let's name it "Firing" and make it Boolean (true/false) for simplicity.
2. In your first event (System > Time = 40 seconds), add the action "Set Enemy3.Firing to True".
3. In that same event, add the actions "Wait X seconds" (X is however long you want it to last) and then "Set Enemy3.Firing to False".
4. In your second event, (System > Every tick), change the trigger from "System > Every tick" to "Enemy3.Firing is true".

This oughta do it. You could also make Firing be True by default and skip step 2, but this allows you to use the enemy in other places without having it explode all over the place.
B
28
S
5
G
1
Posts: 62
Reputation: 2,392

Post » Thu Aug 20, 2015 4:18 am

Hi guys, thanks much for your help so far.

@BlackHornet your capx is very insightful and i learned something from it. It does solves the problem of having the sprite come into the screen and then starts firing for X amount of time. The sprite has the rotate behavior so the bullet patterns works the same as my current setup, in my above event screenshot i created another black square sprite called Enemy3bulletswirl and is set as invisible.

So the black sprite is the one rotating and firing the bullet instead of the actual ingame sprite.

The reason being if i were to give set Enemy3 (Ingame Sprite) itself as that or give it a rotate behavior then my enemy will be spinning even thou it does fires the swirl.

I have tried incorporating your events into mine in the attached above screenshot but it doesn't work, i'm not sure if this conflicts with the "pintoimagepoint" behavior which i'm using or the "moveto" behavior.

@MikeMead @LittleStain i think both of your suggestions are about the same and i tried to follow, up to the point where i don't really get it for @MikeMead suggestion in point 4

4. In your second event, (System > Every tick), change the trigger from "System > Every tick" to "Enemy3.Firing is true".

I can't seem to find any option to get "Enemy3.Firing is True" the bootlean or any other option doesn't have that. I did went through all of the system events.

I'm really thankful for your help so far guys but i do would like to apologise if my questions seems too noob, i have learnt a lot while developing my game and am still learning everyday reading the forums :)
B
11
S
2
Posts: 61
Reputation: 704

Post » Thu Aug 20, 2015 5:18 am

ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Thu Aug 20, 2015 7:05 am

@blackhornet thanks alot for your help! It finally works! I did some improvements also for my sprite to come into the screen > stop > then fire instead of it firing immediately once it pops into the screen.

Thanks all for your help guys, very grateful. I have attached screenshot for the working event and hope it helps some others who has the same problems.

Image
B
11
S
2
Posts: 61
Reputation: 704

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests