Fire one bullet at a time on keydown

Get help using Construct 2

Post » Fri Feb 15, 2013 2:00 pm

Hiya

I think this should be simple but can't work out what I am doing wrong.

On spacedown I want to spawn a bullet, but only allow one on-screen at the same time (so fire rate increases if shooting something nearby).

I thought this would work but it doesn't:

* NOT Bullet on-screen
* Spacebar down
= Spawn Bullet


Nothing happens.
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Fri Feb 15, 2013 2:27 pm

The problem with that is that it will keep spawning bullets if there's any bullet off-screen.

You could have:
[code]
Bullet: Is on-screen

Else
Keyboard: Space is down
   -> Create bullet
[/code]

or give your bullet 'destroy outside layout' behavior and only fire when
Bullet.Count = 0
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Feb 15, 2013 4:38 pm

Actually it's not firing any at all, and I do have the bullets set to destroy outside layout. So as far as I can see my logic *should* work.

Yours looks to be identical logic done in a different way but I'll try it anyway.. thanks. :)
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Fri Feb 15, 2013 4:46 pm

Yeah your way works, thanks! I have to say I don't fully understand why mine doesn't work, I can't see a logic error. Do you think it should be recorded as a bug?

* NOT Bullet on-screen   < is true!
* Spacebar down   < is true!
= Spawn Bullet < doesn't happen!
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Fri Feb 15, 2013 6:54 pm

Oh yeah, if there are no bullets the first condition will be false.

I guess it's kind of confusing but "Bullet: NOT on-screen" will only be true if there are bullets that aren't on the screen.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Feb 16, 2013 11:05 am

But that's my point, it isn't confusing at all. I inverted the statement to be a NOT condition, thus the question;

"There are NOT any bullets on the screen" should return true.

I'll submit as a bug just to see if it's me being silly or not. I hope not after 20 years of programming, lol. :)

B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sat Feb 16, 2013 12:30 pm

Wouldn't it make more sense to have a variable on whatever is shooting and have it be false when the bullet is made and true when you can fire, so you would have something like.

On space down
     Variable = true
           < call.function(shoot)
                 Function shoot = spawn bullet & set variable to false.

then have.

On bullet destroyed < set variable to true.
B
23
S
5
G
1
Posts: 82
Reputation: 2,298

Post » Sat Feb 16, 2013 3:27 pm

Yup that would work too, though it's debatable if it makes more sense to do it that way ;)

I've reported a possible bug with the "negative on-screen" check and am using ramones "else" approach in meantime.
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sat Feb 16, 2013 6:42 pm

[QUOTE=silkc2]
"There are NOT any bullets on the screen" should return true.
[/QUOTE]
See it's not really "There are NOT any bullets on the screen", it's more like "There are (one or more) bullets that are not on the screen".

You're not asking "are there no bullets on the screen?", you're asking "are there any bullets not on the screen?".

It's like the condition "Player: NOT Platform is moving" will be false if there is no player object. It's not "are there no players moving?", it's "is any player object not moving?".
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Feb 17, 2013 4:49 pm

[QUOTE=silkc2]

* NOT Bullet on-screen
* Spacebar down
= Spawn Bullet


Nothing happens.[/QUOTE]

Did you destroy all bullets outside layout first - before the Bullet NOT on Screen Condition? (Specifically you want to destroy the bullet sprite stored offscreen) otherwise Bullet NOT on screen will always return TRUE
B
9
S
4
G
4
Posts: 6
Reputation: 3,518

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests