Can someone explain what happens when a function calls a function

0 favourites
  • 7 posts
From the Asset Store
Basic clone of a 80's arcade game called Gyruss that was quite fun to play!
  • I wanted to see if I could call a function with another function, alas, it works.. Kind of. At least not what I had in mind. I wanted every 1 second to call the first function that would:

    1. Call a 2nd function that would prepare a sprite (bullet) to be pinned to an invisible sprite and position it at a certain imagine point, set a rotating motion to the sprite. then

    2. Set the angle of motion and speed that is listed in the first function

    What I get is, the first function is called, then second function is called to create the bullet, start spinning etc. but it does NOT set the direction and speed as I thought. It waits 1 seconds to send the first created bullet on its way then creates another bullet which hangs out for a second.

    Can someone walk me through what is going on and why the bullets are being created but the speed and direction are NOT set at the same time?

    The link at the bottom should have a Capx.

    https ://drive .google.com/open?id=1PIcyflt3Lxos5Mm91oNh210tGy_iP-aB

  • This should be one event, every 1 seconds with the actions on the right in order. You are not passing any values through so there is no need to use functions.

  • I understand what you are saying, but I am still curious as to why the code seems to skip the set angle of motion and speed for 1 second in the function on line 15. I guess I am looking more for why is it doing that rather than how should I do it.

  • The why is probably to do with picking, when you call a function and refer to an object it does not necessarily refer to any previous objects picked before the function was called. So the spawned invisible sprite in the pin function is not the same invisible sprite referred to in the main function.

  • Ahh ok thank you Plinkie!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, the invisibleSprite instance created in event 16 will not be available yet in event 15. You need to wait one tick for it to be added to layout (insert "wait 0" before changing bullet properties). Or explicitly pick the sprite instance by UID.

  • I was thinking that calling the function would "jump" to the function and run it, then come back to the the line under the function. I already have some other ideas to try now. Thanks everyone!

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