Family Scope & Family Count inside loop

Bugs will be moved here once resolved.

Post » Fri Feb 24, 2017 4:31 am

Problem Description
Don't know really if this is a bug or a C2 expected behavior. I know there is some particularities about "create objecto scope" but I couldn't find the right answer or similar posts about it.
So, the thing is that Family objects list is not properly updated when creating Family objects inside a loop and you want to use the new members with "Family actions" but this "problem" is not coherent with Family count because it does count the new members.
It happened in one of our projects so I prepared a blank C2 project to "prove it". If this is not a bug, at least will be useful to understand this kind of C2 behavior.

Attach a Capx
https://www.dropbox.com/s/qt3bi89asjpp5 ... .capx?dl=0

Image

Description of Capx
Use of destroy only to prove that Family was not updated after loop finish and the Family count is wrong (?)

Steps to Reproduce Bug
  • Just play the project.

Image

Observed Result
1. Only two squares (blue ones) are destroyed, even if a lot of Destroy action types are after or inside the loop.
2. Family.Count counts 8 squares even if it does destroy two of the squares (blue ones).
3. Only a wait action seems to work with Family objects updates.

Expected Result
1. All squares are destroyed.
2a. Family.Count inside loop: 4, 2, 2
2b. Or Family.Count inside loop. Being coherent with the problem about not destroying all squares: 4, 4, 6.

Affected Browsers
Not important.

Operating System and Service Pack
Not important.

Construct 2 Version ID
239 & 243
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,613

Post » Fri Feb 24, 2017 7:07 pm

@Ashley can you help me with this?
What Am I doing wrong?
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,613

Post » Fri Feb 24, 2017 8:30 pm

I think that the 'sprite.count' expression always counts the newly created objects.

'Sprite.PickedCount ' Is not counting in the newly created objects before using a new root event, because it depends on a pick condition. 'sprite.count' Does not depend on a pick condition.

That "create object scope", you talk about, is all about not able to pick newly created objects. (except by UID) before the next root event.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Feb 24, 2017 8:50 pm

Here are two posts that explain how picking works with created objects:
picking-problem_p517685?#p517685
objects-spawned-in-function-don-t-exist-after-call_p837060?&sid=b34f50f7652658da5993db624ad33a0d#p837060

It doesn't explicitly mention families but the created sprites aren't added to the family to be pickable until a top level event as well.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Fri Feb 24, 2017 8:53 pm

R0J0hound wrote:It doesn't explicitly mention families but the created sprites aren't added to the family to be pickable until a top level event as well.


I did think of that for a moment, but I got confused when the "wait and destroy" in the same scope worked.
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,613

Post » Fri Feb 24, 2017 9:09 pm

This would not work if the created sprites aren't added to the family to be pickable until a top level event ?
(Thats is just a question)

https://www.dropbox.com/s/u23pivjynifv9 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Feb 24, 2017 9:25 pm

After a wait the object scope is re-evaluated. The newly created sprite is still picked but all the family will be picked because you didn't explicitly pick any family instances.

Consider the three examples below. When you don't explicitly pick an object type it assumes all of them are picked. The first two examples both just destroy all the family instances after the wait. The third picks a family instance, so that is remembered after the wait, and only that instance gets destroyed.

Code: Select all
start of layout
--- create sprite
   blank-sub-event
   --- wait
   --- destroy family

start of layout
--- create sprite
   pick all family
   --- wait
   --- destroy family

start of layout
--- create sprite
   pick family instance 0
   --- wait
   --- destroy family
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests