playMaker

Author Topic: Understanding Array Get Next  (Read 4608 times)

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Understanding Array Get Next
« on: September 11, 2018, 01:04:38 AM »
I have a state where an Array that contains all the wheels of a vehicle is scanned, and another action adds torque to the wheels, but I can't understand how to make it work properly.
If the loop is active, it seems the array will work inside itself until it's over, then move onto the next action with just the last selected object.
On the other side, if I try anything different, I will occur into other problems, like excess loops or inefficiency because of switching states... I think this all should happen in a single state.

I think I should not use the LOOP inside the Array Get Next, but do it after the torque has been applied, but there's no LOOP action to add.
In fact, if I remove the LOOP at the Array Get Next action, only the first wheel will rotate, while with LOOP active, only the last wheel rotates.
How do I solve this thing?
« Last Edit: September 11, 2018, 11:49:44 AM by megmaltese »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Understanding Array Get Next
« Reply #1 on: September 11, 2018, 04:11:53 AM »
Hi,

 you need to have your arrayGetNext on its own in the state, and transition using Loop and Finished event event  to move to other states.

in the Loop state, you do all you need to to do for the given item passed from the action ArrayGetNext ( the result field).

 does that make sense?

Bye,

 Jean

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #2 on: September 11, 2018, 07:13:23 AM »
Did as you suggested, but I also have to put a "RELOOP" at the end of the "FINISH" transition in the ARRAY GET NEXT, as the state should not exit until the player releases the button, it's not that I want to leave the state after the loop is done, this loop must be done as much as the player doesn't release the key.

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #3 on: September 11, 2018, 07:16:32 AM »
I am afraid Playmaker doesn't get this situation in solution and at the moment this can only be made by setting up 8 variables (wheels can be up to 8 ) and the related number of ADD TORQUE actions for each variable in a state :( and eliminating completely the ARRAY GET NEXT action.
« Last Edit: September 11, 2018, 07:22:04 AM by megmaltese »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Understanding Array Get Next
« Reply #4 on: September 11, 2018, 10:30:06 AM »
Hi,

 do you mean you want to add force every update on all objects in an Array, in one state?

and it doesn't work if you use multiple states?

 Bye,

 Jean

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #5 on: September 11, 2018, 11:33:39 AM »
Have you seen the screenshots?
With that setup I get the "too many loops" error.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Understanding Array Get Next
« Reply #6 on: September 12, 2018, 01:13:16 AM »
Hi,

 yes, because you do that without waiting the next frame once you have finished looping.

 looping an array takes less time than the length of a frame, so once you have finished looping, go to a state with a next frame event, and start again the next frame.

your screenshot is confusing because you are using the loop event it seems. and so it's not clear with just that screenshot what you want to achieve in terms of flow.

 Bye,

 Jean

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #7 on: September 12, 2018, 08:39:35 AM »
OK.

Btw, I have a situation now where I can't drag an GameObject to a field that waits for a GameObject.
Any idea why this is happening?
The field is red, waiting for a GameObject, but when I drag it there, it remains unresponsive.
Never happened before.
The action is ADD TORQUE, but I suspect this is global. Going to check it now.

It's global, it's official: I can't anymore select objects by grabbing them onto actions.
Any idea what can cause this? --- Just tried in another project and it works. Uffffff...
« Last Edit: September 12, 2018, 09:04:47 AM by megmaltese »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Understanding Array Get Next
« Reply #8 on: September 13, 2018, 01:37:22 AM »
Hi.
It is because your fsm is a template.

They are like prefabs on your project folder, they can't communicate directly to scene objects.

What playmaker version are you using?

normally it should show an error message :


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Understanding Array Get Next
« Reply #9 on: September 13, 2018, 02:47:13 AM »
Hi,

 yes, I was about to say, it's because you are editing the template itself, make a variable, expose it to the inspector, and then from the fsm that uses this template you can reference as usual .

warning, refresh your fsm using your template when you change the variable inspector flag, and watch out for mixed up vars, there is a known bug where inspector variables may get mixed up as you add more of the same type, and references can get swapped between variables exposed to the inspector.

 Bye,

 Jean

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #10 on: September 13, 2018, 03:36:00 PM »
Uhm, it's strange, because I'm working with templates since days and I didn't meet this problem before... I'll keep you informed.

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #11 on: September 24, 2018, 04:20:36 PM »
Back on track!

Soooo...

I am afraid Playmaker doesn't get this situation in solution and at the moment this can only be made by setting up 8 variables (wheels can be up to 8 ) and the related number of ADD TORQUE actions for each variable in a state :( and eliminating completely the ARRAY GET NEXT action.

Any idea on how I could solve this?
Scan through an array and apply torque each frame on each of the objects in the array?
It goes into loop count exceeded error.

If I put an Array Get for each of the wheel, then there's another problem: the Array Get only gets done one time in the state, while the Add Torque gets done continuously at each frame.
And then I exit when the player releases the key.
I can't see any way to make it work by using an array of objects.

The only way that comes to my mind for now is to strip away the loop cycle through the array, put all the wheel objects in their respective variables (wheel 1, wheel 2, etc.) at the beginning of the FSM, and then have a state where the torque is applied to all these objects with direct link to the variable... but this would be really ugly to see and maintain.

Can you please help?
I think this is a case that should be handled by Playmaker, while at the moment I don't think it can.

I can send you the package so you better understand the problem.
« Last Edit: September 24, 2018, 06:29:47 PM by megmaltese »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Understanding Array Get Next
« Reply #12 on: September 25, 2018, 02:44:43 AM »
hi,
You can add a state with a 'next frame event' after the finished event (from the array get next)

The 'add torque' should only happen once every frame (on each object)
Without the 'next frame event' it keeps looping and standard, the loop limit is set to 1000 (which can be override in the Fsm tab, but not recommended in this case)

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #13 on: September 25, 2018, 03:16:07 AM »
I still can't understand how all this flow should work, so maybe better I look for a simpler solution.

I was trying to use the HAS CHILD action, but it's not recursive.

The only RECURSIVE action available is GET NEXT CHILD RECURSIVE... and this will have me again produce 8 repeating flows to store the 8 wheels into their variables.

The ideal would be an action HAS CHILD RECURSIVE, so that I could just write the name in there and it would scan all the children and store the object right away.



Sorry for asking, but am I the only one who needs such complex actions?

I'm sorry to annoy you, but I am on a game where the vehicles can have an elastic configuration and the various parts can be "anywhere" in the hierarchy, and in a variable number from 4 to 8... so I need a recursive system to trace the objects without getting mad!
« Last Edit: September 25, 2018, 03:20:03 AM by megmaltese »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Understanding Array Get Next
« Reply #14 on: September 25, 2018, 03:27:12 AM »
Hi.
From what i understand you are spawning a prefab and need to get the wheels right?

Don't use the has child or get next child.

In the main parent from the prefab have an array with all the wheel objects. (name it 'wheels' for example)

Then when you spawn the object , store it in a variable.
Then use 'get fsm array' to get 'wheels' array on the prefab.

if you have different vehicles use the same array name for the wheels.