Hide the children of a structure variable

I have 3 types of ammunition boxes (small, medium, large) based on the size the probability of finding more ammunition increases.
I would need to hide 3 children (“ROUNDS”,“GASOLINE”,“ROCKETS”) only when the small ammunition chest is opened.
the only item I found was the elimination of the children but this determines the elimination of the quantity found in general in the chests.
do you know how to help me?

Can you save those anywhere else, delete them, retrieve them after the loop?

Instead of hiding the items, you could ignore them. If you give your casseami objects a variable like caseSize and each ammo type the same variable then you could compare the case size before adding the ammo name to the array. Since you would be changing the case size, the random name array would have to be cleared each time.

To test this I created 3 casseami objects and gave them each a different value for caseSize.
1 is small, 2 is medium and 3 is large

I gave the items in ammo the same variable
Save.ammo.pistol.caseSize is 1
Save.ammo.rocket.caseSize is 3

Inside the for each child event you can compare the value in the array to the object variable. I used <= so if it’s 1 then it only adds the small (1) but if the object variable is 2 then it would add both small and medium (1 and 2) and if it was 3 it would add all 3. You can use different conditions if you want it to behave differently. You could use equals instead or maybe add some bias or other strategy.

This would make sure the large (3) only contained large while allowing 2 to also contain 1.

1 Like

Hi @Keith_1357,
what I need is to exclude the possibility of finding “ROUNDS”, “GASOLINE”, “ROCKETS” ammunition from the first chest, while in the second and third chest the complete search for all the children present.

I know I’m a pain but could you share a little example?

This should work. Ignore the previous post.
This uses a Boolean to track if it’s the first cases, the events after the fill array event would be the same.

I followed your suggestion but it doesn’t seem to work, when I open the small boxes the 3 children to hide still appear (rounds, gasoline, rockets)

Compare the & events, yours is missing the boolean is false condition.

If true add all items

If false and the text is not one of those items then add item

1 Like

you’re right… i’m clumsy
I corrected the error but I still find them in the boxes

Let me check if I understand what this is doing. It’s opening 3 chests (cassermi) and 2 items per chest. I think that’s the issue. I didn’t take into account both picks from the 1st chest, just the very first pick.

You might be able to move the set firstChestOpened to true outside of the repeat 2 times. I’m not sure if that would fix it. The other option would be to switch the variable from a Boolean to a number. Then add to the variable. Then instead of using true or false, you would check if the number is say greater than 2 or something like that. I really don’t have the time today. It’s close. Keep workinh on it.

1 Like

I tried both to remove the repeat 2 times and to change the boolean variable to a number but it doesn’t work the same…

Am I right about your goal. Are you opening 3 chests with 2 random power ups per chest?

How about posting the changes you made. It’s very close to working.

yes, there are 3 chests with two random powerups inside.
what I need is to exclude the possibility of finding rockets, rounds and gasoline from the first chest.

this is the current code

these are the changes I made previously but they don’t work:

change from boolean variable to number

this is an attempt by removing the repeat 2 times

The version where the Boolean was changed to a number is very close. It’s no longer counting crates but powerups.

I’m still not totally positive. It’s difficult just looking at the code. I had to rewrite it because the counter needed to go up each time. Since the counter is now increased before the array is built the numbers needed to be increased. So, now. 1 and 2 are the first case

1 Like

ok now it works the only problem is that sometimes the same powerups are found in the chest

If it’s working. It doesn’t refill the array until it’s empty. That prevents multiple items from being picked. But, when the array is exhausted, it refills the array. So, if there were 5 items then the first 2 cases should be fine but the 3rd case would have the last item from the array and 1 item from a new shuffle. There will be times when the last item is the same as the 1st item in the next shuffle.

Think of it like shuffling a deck of cards. When you deal the last card and then reshuffle everything, the first card of the next deal could be the same cards. It’s unlikely with 52 cards but more likely with only say 6 items.

I guess if they were the same, you could take the next item from the array. If you used a variable to check the last pick, you could compare it to the first pick on the new shuffle. Then either skip it or swap the first child with the last. Or something. I’m really not sure what’s the best method.

I guess another strategy could be to make sure there’s always at least 2 cards in the array before a chest is opened. I honestly don’t know. Maybe the entire strategy needs to be rethought. The first strategy isn’t always the best. You can’t always plan for every possibility.

1 Like

I happened to be thinking about this and I think the easiest way to do this would be to check the size of the array. If it’s an odd number than add another item to the list. You could add the value of the 1st item (since arrays start at zero it would be [0] )

This would go after the for each child that creates the randomNamesList, it would be on the same level as the event meaning even margin wise and not a sub event because you want this to run after the array is built but only when the list is being built.

See the red line, it’s a new event not a sub event.

The condition would be
compare 2 numbers
mod(number of children in the array randomNamesList, 2) = 0

The action would be
Add text randomNamesList[0] to array variable randomNamesList

(FYI… mod(#, #) is modulo, it divides the first number by the 2nd number and returns the remainder or the number should the 1st number be less than the 2nd number)

1 Like

Hi @Keith_1357 Keith, thanks for your time
what is not clear to me is that there are no children in the randomNamelist array.
There are 10 children found in the save.ammo structure variable
If what I entered is correct it still doesn’t work.

The event with one of these is true is 1 or 3, I should’ve had delete the children of the randomNamesList array.

That wouldn’t stop it from working though, that would just prevent the old list from being cleared so it generates a completely new list.

The array will show empty on the setup screen. It gets added at runtime. You would have to check the debugger while it’s running to check the variables.

The mod() condition should be
mod(number of children in randomNamesList, 2)
The expression not the actual number)

That also shouldn’t stop it from working that’s to prevent duplicate items.

Try making those changes and let me know what is or isn’t happening.

I think I didn’t understand how to search for the number of children in numberNamelist

I forget the expression is different than the condition. Sorry. I usually type “count”

You can start to type “count” it’s “VariableChildCount”

It’s “number of children” in the expression builder.