How do I properly call a function within a function?

  • I'm trying some tests with functions to understand them better. In this example, I'm calling a function that creates a box. Within that function is a call to another function to immediately change its opacity.

    When I call the function "createbox", the box is created, but the opacity isn't changed ("fader" is not working). However, if I remove the "fader" call and assign it to its own key (like 'On F released, call "fader" (green), then it works. But, shouldn't it also work within the "createbox" function? Thanks.

    [attachment=0:1xqg3zsj][/attachment:1xqg3zsj]

    [attachment=1:1xqg3zsj][/attachment:1xqg3zsj]

  • You can do "Green -> Set opacity to Function.Call("fader")"

    And on function "fader" you do the Function return value to whatever the opacity value you want

  • You've come across the classic "can't pick newly created objects" problem. The universal solution would be a "Wait 0" before your other function call, but I personnaly hate that. I really prefer the "Pick by UID" solution. The "Pick by UID" condition is unaffected by the "can't pick newly created objects" constraint.

  • Thanks guys. Both suggestions worked out.

    Magistross Is there a functionality reason to avoid Wait 0, or is it more of a coding practice thing?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wait 0 pushes the remaining actions at the end of the tick, thus interfering with the normal flow of the game logic. I prefer my code to execute when I want it to, and not being forced to execute it later. But in the end, I guess it's more or less a preference in coding practice.

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