playMaker

Author Topic: Array List Get Next confusion  (Read 201 times)

curb47

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Array List Get Next confusion
« on: January 26, 2021, 05:09:38 AM »
Hello,

I'm having some problems setting up a reliable Array List Get Next FSM. I've found a thread on the forum which explains it clearly, so I understand what's going wrong, but I don't know how to fix it.

The problem is that the Array List Get Next action skips or misses some objects in the array, if the objects are de-parented and/or destroyed before the array get next list is complete.

Which is exactly what's going on in my Loop, the objects (enemy spaceships) can be shot/destroyed as the list is being run, and they are being de-parented, so the Array List Get Next fails to complete quite regularly.

Here's the Array List:



And here's the State/Actions in the Loop:



I have found a little work around; after the Finished event I put in a state which tests whether the Array is empty, and if not sends it back to the Array List Get Next state to finish it off. The problem with this is that it breaks the timing of the sequence, I have 10 enemy spaceships peeling off one by one from a pre-defined flight path, and it looks rubbish when the array list stops/checks for a moment.

So. How do I get round this? The other thread i found offers the outline of the solution, but I can't get my brain around it.

Here is the other thread:
https://hutonggames.com/playmakerforum/index.php?topic=21707.0

Thank you in advance for any help.

J.
« Last Edit: January 26, 2021, 05:14:21 AM by curb47 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6003
    • View Profile
    • jinxtergames
Re: Array List Get Next confusion
« Reply #1 on: January 26, 2021, 07:04:34 AM »
hi.
You deparenting and destroying but not removing from list, right?

after Get next (before Deparent) use 'Game Object Is Null' this way you can check if the object is still there.

curb47

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: Array List Get Next confusion
« Reply #2 on: January 26, 2021, 07:19:42 AM »
I'm de-parenting but not destroying on this FSM.

Destroying/removing from List happens on a different FSM (local to the enemy ship)

On the FSM in this thread ^^^ I need the objects to de-parent, but stay on the list. If they are shot (destroyed) they are removed/despawned elsewhere.

The 10 enemy ships go through a 3 stage attack routine, and i need the list to remain intact (unless an enemy is shot/destroyed/removed from list) so that I can pass on additional instructions to the objects in the list for the next attack stage.

Make sense?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6003
    • View Profile
    • jinxtergames
Re: Array List Get Next confusion
« Reply #3 on: January 26, 2021, 04:41:19 PM »
Hi.

if you remove from the list you can send an event to recheck the array.
if you do, connect a bool on the reset and set it to true before you loop. this will reset the loop starting back from the start index.

also its best not to use 'Finished' transition when the loop is done. use a custom transition (for example 'Done')

other things you can do is to have a 2nd array with bool to check if de-parented or not.

for this you can get the index from the get next and use Array(List) Get and use the index number.

curb47

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: Array List Get Next confusion
« Reply #4 on: January 27, 2021, 12:35:09 PM »
Thanks djaydino,

I'll be back on it tomorrow morning, so will wrap my head around your suggestions and give it a shot.

Thanks again.

J.