playMaker

Author Topic: Get Next Child finishes on first loop  (Read 3708 times)

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Get Next Child finishes on first loop
« on: March 26, 2013, 08:05:21 AM »
Hi,
I've got an FSM where I'm attempting to use GetNextChild twice in two different states. I'm looping over children with GetNextChild to do a set of actions in the first state, then once complete, I go into another state, which also uses GetNextChild again to perform different actions on the same children. The loop event never goes off on this second state, despite there being children on the object.

I wonder if Playmaker sets a flag saying there's no more children after completing the first run through, and if so, how do I get around this?

I noticed Jean posted an updated action for this, but I should have that as I grabbed the latest version of playmaker not long ago?

Thanks!
Jay

greg

  • Junior Playmaker
  • **
  • Posts: 68
Re: Get Next Child finishes on first loop
« Reply #1 on: March 26, 2013, 11:08:46 AM »
I remember having issues with get next child, so i just programmed the searching myself for a quick fix.

- on first state it gets "#children the object has"
- then it checks child by "index number"
- check if this is this the right child we're looking for?
- increments "index number" by 1
- if "index number" = "#children the object has" then object doesn't have the child
- if "index number" < "#children the object has" then go back to start of state because there's more children left to check


Hope that helps.
« Last Edit: March 26, 2013, 11:10:45 AM by greg »

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Get Next Child finishes on first loop
« Reply #2 on: May 13, 2013, 04:55:00 PM »
I am having the same problem.
I want to loop through children and toggle visibility.
It only works on first child.

I set up this way.
First state:
FIND GAME OBJECT
GET CHILD COUNT

Then it goes to the following state where I only have:
GET NEXT CHILD
SET VISIBILITY

In GET NEXT CHILD I also tried to let it loop infinte but it simply doesn't work.

I also tested with a hand made loop and it was definitely looping because the number grown up to 75, which is correct, but it looks that the GET NEXT CHILD action is corrupted somehow.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Get Next Child finishes on first loop
« Reply #3 on: May 13, 2013, 05:34:56 PM »
Though i'm not sure what to say about the action but i think you can get the child by it's index number. if you know how many children it has (assuming it's not going to change before this algorithm finishes) you could get by number.

so, you can iterate through each of the children in an orderly manner this way. not sure if this will resolve what you're facing though so your mileage may vary.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child finishes on first loop
« Reply #4 on: May 14, 2013, 03:39:39 AM »
Hi,

 GetNextChild action holds reference to the index privatly and it's not static, so I don't see how a different state would be affected by a previous use of this action.

If you have a repro thatz you can share with me, send it over, I'll have a look.

bye,

 Jean

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Get Next Child finishes on first loop
« Reply #5 on: May 14, 2013, 04:24:03 AM »
OMG just found out why.

I had SET VISIBILITY put AFTER GET NEXT CHILD.

So the loop didn't allow the SET VISIBILITY to be called.

The GET NEXT CHILD action must be the last in the state for things to work!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child finishes on first loop
« Reply #6 on: May 14, 2013, 04:33:47 AM »
Hi,

 good point, I assumed that actually. GetNextXXX should always be the only action on this state. Do stuff based on states triggers by these events.

bye,

 Jean