Foreach count of newly created objects

0 favourites
  • 11 posts
From the Asset Store
Be quick and count the cards and choose the right number!
  • Hi all

    I have a problem in my game trying to do a foreach loop on some created objects. I'm not 100% sure it's the same problem, but I'm wondering if it's related too this breaking change.

    Screenshot from R104. Also tested in R105.

    <img src="http://i.imgur.com/CsREd.png" border="0">

    Weirdly I had some similar code in my game that worked, but broke in R105. From the test above it should never have worked in the first place! Was there any changes related to the R100 breaking change that was made more strict in R105? Is it just luck that I had code similar to above that worked in R104 and broke in R105?

    Cheers.

  • Anyone have any ideas? This will be the one and only bump I'll do on this.

  • This fix in r104 should mean this works properly:

    reaking change: Object's 'Count' expressions are now immediately updated inside loops and subevents when new instances are spawned or created, contrary to the fact these instances do not really exist until the next top-level event. This may help fix projects broken by the last breaking change which depend on object counts in subevents, but unfortunately may again break projects which already adapted to the new behavior. Sorry - in the long run it's for the best that we make these changes.

    So it's strange that it doesn't. I don't believe r105 changed how it worked. Can you post a .capx?

  • Here is a sample from R104:

    https://dl.dropbox.com/u/20830426/ForEachCount_R104.capx

  • So did this turn out to be a bug or am I doing something wrong?

  • Last bump

  • i have some similar problems too, especially with families

  • Yeah it's because of the change you linked to in your first post. The objects created in event 2 can't be picked until the next top level event. So in event 3 there is only 1 sprite - the initial one. Though sprite.count would still return the correct number (60).

  • See now when I heard the term top level event, I figured it meant the top level of the event that spawnd the objects - in this case line 2 would be the top level event for the object creation. Is the keyboard trigger the actual top event? How would you get around this then if you were creating objects inside a while loop?

    The issue I'm running into in my game is I have a while loop that, depending on conditions, spawns 20-30 objects. I then assign an instance variable to them and use them in a foreach statement further down. If I need to return all the way to the top level event, I don't see how I would use a while loop unless I split it into two or three while loops. Is this just the expected way it should work?

  • A top level event is one that's not a sub-event of anything. There's another thread here where R0J0hound links to a picture from CC that explains it.

    It depends what exactly you're trying to do. You could either do whatever you're doing in the for each loop inside the while loop instead, immediately after the sprite is spawned. Or inside an 'on created' trigger. Or you could set a variable true when the sprites are spawned and have a top level event 'var = true/ for each sprite' -> do stuff.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Late reply, but I just wanted to say that picture from R0J0hound explained it really well. Line 5 is exactly where I seem to be having trouble.

    I was able to get it all working once I understood that, thanks for the help ramones <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)