playMaker

Author Topic: Extract all content from an array into separate variables[SOLVED]  (Read 3851 times)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Hi,
I'm sorry that his must be a very stupid question but I can't wrap my head around the best solution.

So I have a Get Next Overlap Circle 2d that stores all the hit colliders in an array. That works great. But now I want to check which one of all these colliders have the closes distance to the player.

I just want to extract every gameobject from the array into each separate variable to be able to apply a Get distance on them one by one.

I feel like the solution should be Array Get Next in some way but I can't really understand how to use it. It overwrites the result-variable with each loop and I do not know how the save the result-variable into a separate variable.

/Christian
« Last Edit: November 25, 2019, 01:26:21 AM by jeanfabre »

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Extract all content from an array into separate variables
« Reply #1 on: November 19, 2019, 11:59:33 AM »
You wouldn't store each game object in a separate variable. You'd use the Array Get Next action to store the current result in a game object and the current index in an int variable, then use that stored result in the Get Distance action. Make sure you store the distance so you can compare it with the next object's distance. You'll need to create some variables...

« Last Edit: November 19, 2019, 02:23:25 PM by ransomink »

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: Extract all content from an array into separate variables
« Reply #2 on: November 19, 2019, 12:21:21 PM »
in the Get Next loop, you want to get info about the current array item (including its index number in the array) and compare this info against whatever you are looking for (such as the distance of the nearest known object).

so for instance, some of the variables you want to save/compare in the Get Next loop:

current_GO_index
current_GO_distance

closest_GO_index
closest_GO_distance

compare current_GO_distance to closest_GO_distance, and save the index number of whichever is closer to closest_GO_index.

Once you've cycled through the array, you'll know which item is the closest because it is the "winner" saved to closest_GO_index.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Extract all content from an array into separate variables
« Reply #3 on: November 21, 2019, 02:05:20 AM »
Hi,

 you are in luck with ArrayMaker, it has an action ArrayListSortGameObjectByDistance which will do that for you, simply put all you objects in an arraylist, define a target for the position to check distance against and you are done :)

bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Extract all content from an array into separate variables
« Reply #4 on: November 21, 2019, 09:53:46 AM »
Hi,

 you are in luck with ArrayMaker, it has an action ArrayListSortGameObjectByDistance which will do that for you, simply put all you objects in an arraylist, define a target for the position to check distance against and you are done :)

bye,

 Jean

Oh okey sound nice! I thought that the ArrayMaker was obsolete/outdated? When I found the array-actions in playmaker I just assumed that ArrayMaker was not needed anymore.

How come there is both ArrayMaker-addon and regular arry-actions in basic playmaker?

I feel like the add-on section in the wiki are just a bunch of old outdated addons that mess up my project if I install them...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Extract all content from an array into separate variables
« Reply #5 on: November 22, 2019, 02:30:24 AM »
Hi,

 ArrayMaker is still very much required in my opinion.

ArrayMaker gives you access to a more flexible list, and hashtable, PlayMaker FsmArray is more constrained on that regards, with a fixed type. I sue both personnaly, switching to ArrayMaker when I need more power for my lists.

Bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Extract all content from an array into separate variables
« Reply #6 on: November 22, 2019, 04:13:10 AM »
Hi,

 ArrayMaker is still very much required in my opinion.

ArrayMaker gives you access to a more flexible list, and hashtable, PlayMaker FsmArray is more constrained on that regards, with a fixed type. I sue both personnaly, switching to ArrayMaker when I need more power for my lists.

Bye,

 Jean

Okey cool! Thanks for they reply