Is this how you check if none are visible?

Discussion and feedback on Construct 2

Post » Thu Dec 18, 2014 10:16 pm

Just wondering if this is the correct way to check if there are no visible objects. It works, but I'm just wondering if there is a better way or not.
How would I make it so it only checks once? Can I add a trigger once while true somewhere? because from what I gather it would do this every tick.
flyerbolt.jpg
You do not have the required permissions to view the files attached to this post.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Thu Dec 18, 2014 10:36 pm

A cleaner way to do the above would be to place the 'stop sound' action under an inverted 'Is Visible' event. Read about inverted events here:

https://www.scirra.com/manual/76/conditions

There may be a better way to handle this, but it would depend on the specifics of the game's design.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Dec 18, 2014 10:38 pm

@TiAm , But that would stop it if any of them are invisible, not if all of them are invisible.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Thu Dec 18, 2014 11:39 pm

how about
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Dec 18, 2014 11:41 pm

edit: whoops, codah beat me to it! 8-) But...I have a capx! So there! :mrgreen:

Ah, I was assuming that you were triggering sounds per-object (don't know why I thought that). In that case my suggestion would indeed fail.

If you want to avoid the 'else', you could do this:

Is NOT visible
Obj.Count = Obj.PickedCount

capx:

https://www.dropbox.com/s/cd141l996flw8 ... .capx?dl=0
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Dec 18, 2014 11:48 pm

Thanks for showing an alternative way. I'm thinking the Else would be quicker since it doesn't require calculating if count = pickedcount, right?
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Thu Dec 18, 2014 11:59 pm

Technically it would be a bit more efficient. In real use, comparing two numerical values every tick is a trivial process, even on a mobile.

The else logic strikes me as being possibly confusing, but that may just be me. Use whichever approach you find easier to understand.

The thing that can kill here is the 'is visible' command. If you plan on having a lot of these objects present in the layout (>100), you should make sure that this logic only runs when triggered, instead of running as a 'dumb test' every tick.

If there will only be a handful of these objects in the game at any one time, I wouldn't worry about it.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Fri Dec 19, 2014 12:00 am

I had a capx just didn't bother uploading it :)

Here's an option that's not every tick. with capx

As far as being quicker.. that's probably a mico optimization. If you can measure any difference in your app.. go for it.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests