How do I call a function after "on created"

0 favourites
  • 12 posts
From the Asset Store
Basic clone of a 80's arcade game called Gyruss that was quite fun to play!
  • First, thank you to everyone who has been answering all of my newbie questions.

    Now I'm floundering on program flow.

    I have something that looks like this

    On Player Created 
    -> configurebays()
    
    On configurebays()
    -> Spawn gun at Player Image Point X
    [/code:2uqfjimw]
    
    However, it looks like on player created is called before the object is actually created (???) so the guns never spawn. If I add a button and call configurebays() after the game is loaded it works fine.
    
    I also tried
    
    On LayoutStart
    -> Spawn Player
    -> configurebays()
    
    but again the guns would not spawn.
    
    So I'm tripping over this issue. I don't have access to my files at the moment but can post the capx or screenshots later (screens might be better)
    
    Second issue I'm battling is sprite vs family instances
    
    On Layout Start
    -> create demogun
    -> demofamily do something
    
    won't work work, but
    
    On Layout Start
    -> create demogun
    On Layout Start
    -> demofamily do something
    
    does work. (?)
  • your player is probably on the layout at the start of the layout, right?

    try something like this

    on start of layout > player.destroy

    wait 0.5s

    System > create player

    On create player > do what you want

    About spawning guns, maybe you should read about containers on the manual / tutorial section.

  • Hi Scofano, I can not use containers because the weapons are dynamic (a player sprite can have any combination of guns on available image points, or no guns at all), unless I misunderstood containers.

    The sprite is not on the layout, it is created with a

    on layout start -> create playersprite

  • I think it should be. At least on the margin space, outside the layout. Whenever I try to spawn or create something that is not on (any) layout, browser sends me an error.

  • heh, I just had a thread about this yesterday. I moved everything out of the margin and into a separate layout for loading that works MUCH better than putting it into the margin, but there is some execution flow that I'm not understanding. I'll upload something soon

  • I believe in you but it makes no sense to me.

    How being on a different "library loader layout" is better than being at the same layout but just on a negative position?

    Can you share the link of the thread? Im curious.

  • All relevent code is in the file "pcturrents", it's sort of a mess because I've been fussing with it trying to get it to work.

    edit: Link to thread about resource loading. The turrets work fine if the player sprite is already on the layout, but I need to spawn it dynamically because the player will be able to choose from various ships.

    Edit again:

    POC, the turrets will work when called later on. If you start the game with F4 choose campaign, swipe to move over the moon, click the commlink, then choose plunder planet, I stuck a call to it there, and it works fine. For some reason, no matter what I do, I can't insert code to run right after the object is created. Help!

  • Bump.

    I'm positive there's a simple solution or a simple mistake I'm making. Proverbial missing semicolon?

  • You can pass the ship UID to the function and then pick the ship by UID in the function.

    Newly created objects aren't properly created until the next top-level eventso it seems the ship doesn't exist yet in the "configurebays" function but you can pick it by UID.

  • That explains EVERYTHING, thank you so much. That just answered other questions I had and didn't even know I had.

    A very easy way to think about it is that scope applies to created instances, but really, rendering does not happen until after event execution so any scope above it does not know the new sprite exists.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Let us know if it worked.

  • Yes, it did! Extremely simple solution. You can force simulate global access by doing

    Action->System->wait 0.01

    Back to work!

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