Unexplained behaviour in recursive functions?

0 favourites
  • 2 posts
  • Hello!

    I have this recursive function

    which prints how many times it was called onto an on-screen Text object.

    The weird thing I observed is that without this "Trigger once" clause, it rapidly updates the Text object every second, e.g. It says "1" for a second then rapidly 2,3,4,5 and then "5" for another second. Then the process repeats.

    With "Trigger Once" present, it behaves as I would have expected : the text field increments by 1 each second.

    The question is why do I need the "Trigger Once" clause to make it behave as expected? How is it getting called 4-5 times per call without the "Trigger once"?

    If someone could explain what I am missing here I would be very grateful!

    Thank you in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct 2 function call parameter values are only available in the function call which is a triggered event lasting one tick. A wait goes beyond the tick, so the value goes to zero after the call.

    I would suggest using instance variables, and timer behaviors.

    It looks like you already have a dummy object that would work.

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