Families in functions

Get help using Construct 2

Post » Thu Jun 01, 2017 2:41 pm

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

Image

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.
B
3
Posts: 8
Reputation: 191

Post » Thu Jun 01, 2017 2:58 pm

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.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Thu Jun 01, 2017 3:22 pm

Ok, good to know. I've never worked with arrays before but I give it a shot.
Thank you!
B
3
Posts: 8
Reputation: 191


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, Yahoo [Bot] and 14 guests