Actions within my return functions run 3 times

0 favourites
  • 5 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hellu. When I do this:

    Print 1

    Print Functions.Underline("2")

    Print 3

    I get:

    1

    2

    3

    But when I include an additional Print action within the return function itself—like Print test—it prints test `3` times..

    1

    2

    test

    test

    test

    3

    I'm not sure if this is intended behavior or by design based on the tick system, but I suspect something may be up. Really what I wish for is to understand why this happens—as just to be clear the function does work, I just need to refrain from using return functions for anything with permanence and instead just use them to return a value. I'm using the latest stable release.

    Tagged:

  • You showed what it does but not what the function looks like. That would make it so others can possibly spot what’s amiss.

  • Of course, it definitely has something to do with my code, I just tested a more bare bones version in a new test project and this outcome I described above did not happen. Below is an example of me using a key word `#comm` that will output COMMON with a teal color I attributed to in a dictionary `Common,139e87`. Once again everything works as intended, but for some reason my console is logging `test` three times instead of once which would make the most sense, as `1` and `2` I logged earlier do not repeat at all..

    I made sure nothing else is calling this function when I run the game. This is the only place the function is called (not to mention this would have generated additional `1`'s and `3`'s if that was the case. And the length of the text passed is 5 chrs, there is no other text being passed so the function above is skipped of course (I confirmed this by disabling it too, doesn't solve it)

  • Oh, I think I see what’s up. Do you have three instances of TextM… ? I can’t see what the rest of the name is.

    Anyways when you set the text of the text object the action is run for all the picked instances. So if you have three instances the function would end up being called three times.

    As a minimal example of this, add a text object and add three instances of it, then add a second text object (text2) to display the result.

    Then with these events you’ll get text2=“testtesttest” much like in your project.

    Start of layout
    — Text: set text to function.parse()
    
    On function parse
    — text2: append “test” to text

    Hope that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ohh I see! That was it I was able to repo. Thanks for the explanation! That was the case. I can be such a perfectionist that even when something is still working—but looks funky and don't understand what's happening—I still wish to understand whats going on haha

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