Families in functions

0 favourites
  • 3 posts
  • Hi,

    I'm working on a strategy game and I try to construct the build-menu.

    Here is the situation:

    When you open the menu there should be a check, if you have enough money (global var "money"). "btn_build_res_th" and "btn_build_res_default" are buttons to build buildings. Both are in a family called "menu_cards".

    When you call the function "check_money" it should check for each element in the family "menu_cards" if its local var "cost" is less the global var "money". If true it should set the boolean var "active" for each element in "menu_cards".

    But unfortunally it does not work and "active" is not set.

    Why it doesn't set the boolean at event 7 for "btn_build_res_th" and "btn_build_res_default" which are in the family "menu_cards"?

    I got a similar problem at another point, where I can't use families in a function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It has nothing to do with family. It's the classic case of "can't pick a newly created object until the next top-level event".

    Since the "Pick by UID" is not affected by this, you could workaround this issue by storing the button UIDs in an array and doing a For Each Array Element -> Pick Button Family by UID. You'd need to clear the array at the end of each tick.

  • Ok, good to know. I've never worked with arrays before but I give it a shot.

    Thank you!

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