Create Object Rule?

0 favourites
  • 9 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • What is the rule about creating a new object? I can't find it anywhere in the doc.

    If On Start of Layout I create 10 objects then the next event I put For Each for those new objects..it doesn't work.

    I think it has to go through the sheet once or something?

    Basically what I'm trying to do is to create a random level, I do it in Start of Layout, but then I need to go through separately modify them based on a different table. I would like this all done in Start of Layout, but its not working and I'm pretty sure it has to do with this rule. Anyone?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is your "For Each" a sub event of "Start of Layout", or a standalone event beneath it?

    The only time 2 standalone events communicate is with the "Else" statement.

    If I understand correctly the "rule" you're talking about is just object selection / object list within events, which should be covered in the manual.

  • jobel

    when objects are created, Construct does not finish adding the new objects to the internal lists until the next top level event. So, when the object is created, it will stay picked for all actions and sub events directly under it. But you can't loop through them until the next top level event, or you can add a "Wait 0 seconds" action before the for loop to make that code run at the end of the current tick.

    the only other thing you can do is pass the UID of the object to a function, and pick the object by its UID - then you could modify each object as it is created...

  • AllanR thank you!

    so I need to do another top-level, so I tried another OnStart of Layout and it worked! thanks!

    I really needed to do this code in On Start of Layout, I already have a bunch of timing things that happen after the layout starts, it would have been a pain to add in extra time just to be able to loop through those newly created object in the game loop.

    however this double onStartofLayout seems like a loophole... do you think its okay to do it this way? Any chance of them both running simultaneously and screwing things up?

  • Think using a container might be more efficient if you're just trying to spawn in groups of objects, no?

  • jobel

    I think that should work fine. It never occurred to me to try that, but it follows the rules. Eventsheets are executed top to bottom.

    like AySquirrel said, a container would be a good idea because then when you pick the main sprite, the spawned sprite will automatically be picked as well. And when the main sprite is destroyed, the spawned sprite will also be destroyed. (any objects in a container automatically get created when the container object is crteated).

    another way to do it (without containers) is to have TestSprite spawn TestSprite2 inside the first repeat (event 2). That way it will create then in pairs, rather than all the TestSprites first, and then the TestSprite2s afterwards.

  • AySquirrel / AllanR no my example isn't how I was using it practically. In reality I am looping through newly created sprites and setting instance variables based on other information that I don't have at the time of creation... hence needing to loop after the creation loop.

    my example was just a test to see if it would run and the quickest way to see it was to spawn another object. If you put Event 4 as a sub event of Event 1 (under Event 2) it will yield no results.

    sorry about the confusion.. in my attempt to be clear I just ended up confusing people!

  • AllanR

    I think that should work fine. It never occurred to me to try that, but it follows the rules. Eventsheets are executed top to bottom.

    true, they run top down but I'm just worried if I have a lot of sub events that take time to run, that the next Start of Layout will happen before the Actions of the first finishes.

  • I am pretty sure it finishes one event completely before it starts the next - unless you add "Wait x seconds" to intentionally delay actions.

    I have heard some people say that triggers can happen out of sequence, but I don't know if that is true or not.

    EDIT: from the manual:

    However, triggers are an exception. See the green arrow to the left of Keyboard: On Space pressed from the previous example:

    Note the trigger.

    This indicates the event is triggered. Rather than running once per tick, this event simply runs (or "fires") upon something actually happening. In this case, the event runs when the user hits the Spacebar key on the keyboard. It is never checked any other time. Since triggers run upon an event happening, they aren't checked in top-to-bottom order like other events. This means the ordering of triggers relative to other events is not important (except relative to other triggers of the same type, since triggers still fire top-to-bottom).

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