If out of ammo AND no bullets on screen restart, not working

Get help using Construct 2

Post » Fri Jan 23, 2015 11:26 am

I want the layout to restart if the player's ammo = 0 AND there are no bullets currently on the screen.

For example the player has 3 shots to hit the target, If he wastes his first 2 shots, then shoots the third bullet at the target, I don't want the layout to restart until the bullet is off the screen, just in case it does hit the target.

I am using this setup currently, it doesn't work but I can't see why not.

Image

Note in my game I have 2 different kinds of ammo, and of course I only want it to restart if the player is out of BOTH kinds. Also note I destroy bullets when they leave the layout, so any workaround must take that into account please :)
B
4
Posts: 22
Reputation: 244

Post » Fri Jan 23, 2015 12:20 pm

How are you testing for this to occur? Its hard to tell from the above screenshot. Every tick, Every Second.. something else ?
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Fri Jan 23, 2015 12:22 pm

spongehammer wrote:How are you testing for this to occur? Its hard to tell from the above screenshot. Every tick, Every Second.. something else ?


Nothing...

I assumed the conditions themselves would be checked by the engine every tick, isn't that how all conditions are checked by default?

I'm pretty new to construct 2 so correct me if I'm wrong.
B
4
Posts: 22
Reputation: 244

Post » Fri Jan 23, 2015 12:28 pm

If the event is a top level event indeed it should be checked every tick.
As SpongeHammer said, it is hard for us to only tell from this very close up screenshot.
It would be better if you could provide your full capx. (Go into Full Editor, tab "Upload attachment" and upload your capx there)
This will make it easier for us to investigate and tell you what is going wrong.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Fri Jan 23, 2015 12:41 pm

Alright, I have attached the capx file to this comment.

It's obviously a WIP and a bit of a mess, but just run any of the numbered layouts and you'll see how it works. There is only 1 event sheet currently.
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 22
Reputation: 244

Post » Fri Jan 23, 2015 2:00 pm

The oproblem is, that you say "when Bullet & Sprite are not on screen" but the problem is, they don't exist, so they are not not on the screen either ;)

You need to test, if any object bullet and any object sprite exists, and if they both don't (and your Ammo is 0) then restart.

https://www.scirra.com/manual/29/object-type

SOL functions
sol.hasObjects()
Returns true if the object type has at least one instance and select_all is true, or if the SOL instances array is not empty and select_all is false, else false.
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Fri Jan 23, 2015 2:54 pm

Hey, thanks for responding... I gotta admit I'm pretty clueless though.

Searching for "sol.hasfunctions()" in Construct 2 brings me no results and googling it didn't really bring me anything I could understand.

I understand what you mean, but I don't know how to actually use it in Construct 2!

Could you be so kind to show or tell me practically how I can apply this to my specific problem?
B
4
Posts: 22
Reputation: 244

Post » Fri Jan 23, 2015 3:54 pm

>@TomCarter : Sorry, my bad, that's not for the use inside construct 2.

As an apology, I tuned your capx-file, as simple, as I would do it.. Maybe this helps you more than just with this specific problem ;)
You do not have the required permissions to view the files attached to this post.
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Fri Jan 23, 2015 5:11 pm

MultipleChoice wrote:>@TomCarter : Sorry, my bad, that's not for the use inside construct 2.

As an apology, I tuned your capx-file, as simple, as I would do it.. Maybe this helps you more than just with this specific problem ;)


Hey! Thank you!

I'll admit I spent about 15 minutes staring at it screaming why isn't it working?! As of course what you're wrote is logically sound...

The thing we both missed is that I start my levels with 1 bullet off screen that is instantly destroyed. This means that before the player fires anything, we get -1 projectile, which means we have 0 projectiles when we still 1 ammo left which causes the game to restart as soon as we fire that last projectile, rather than when it's destroyed like we want.

Very simple fix of course, I simply made Projectiles start at 1 instead of 0. I also did some clean up stuff like having it be set to 1 when loading any layout so it works for the rest of the game, just mentioning this in case anyone else with the same problem reads this thread ion the future and is confused :P

Thanks again for your help.
B
4
Posts: 22
Reputation: 244

Post » Fri Jan 23, 2015 6:03 pm

The thing we both missed is that I start my levels with 1 bullet off screen that is instantly destroyed. This means that before the player fires anything, we get -1 projectile, which means we have 0 projectiles when we still 1 ammo left which causes the game to restart as soon as we fire that last projectile, rather than when it's destroyed like we want.


Yeah, I have overseen that ;) I prefer to have a separate Object layout, to spawn them on demand, not having such confusions at all... I would recommend that to you as well. Try to keep things logical. Like if there is no Bullet shot, the Value should be 0. Such a minor thing can cause great confusion later, can be overseen for example :D

Happy, it still helped!
B
8
S
3
Posts: 197
Reputation: 1,207


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest