playMaker

Author Topic: Proper Way to compare Int from multi Objects (Solved)  (Read 2610 times)

Captaincrud

  • Junior Playmaker
  • **
  • Posts: 72
Proper Way to compare Int from multi Objects (Solved)
« on: May 26, 2016, 09:42:58 PM »
I have multiple objects add them self to a array at beginning of game I need to order the array from highest INt score to lowest for a turn order.
« Last Edit: May 27, 2016, 10:31:41 PM by Captaincrud »

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Proper Way to compare Int from multi Objects
« Reply #1 on: May 27, 2016, 01:35:57 AM »
Usually you can just sort the array- then reverse it- then get the item at index 0
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Captaincrud

  • Junior Playmaker
  • **
  • Posts: 72
Re: Proper Way to compare Int from multi Objects
« Reply #2 on: May 27, 2016, 01:50:16 AM »
OKay let's say i'm setting 9 floats in each object, I need to get the 5th float from each of these objects and sort the array from top float value to lowest. So basically they are all characters I need to get their initiative to see the turn order.
« Last Edit: May 27, 2016, 02:02:46 AM by Captaincrud »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Proper Way to compare Int from multi Objects
« Reply #3 on: May 27, 2016, 03:25:51 AM »
Hi,
You should check these tutorials out : ArrayMaker Tutorials

Tutorial 2 might help you out

Captaincrud

  • Junior Playmaker
  • **
  • Posts: 72
Re: Proper Way to compare Int from multi Objects
« Reply #4 on: May 27, 2016, 04:19:29 AM »
Yeah that works great if my whole deal is a single  float but its not its a game object with around 10 floats tracked on it for combat.

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Proper Way to compare Int from multi Objects
« Reply #5 on: May 27, 2016, 12:54:24 PM »
For this solution, you'll need 3 Arrays.  Your Game Object Array, your "Comparison" Array and your Sorted Game Object Array.

To start with, you use "Array Get next" to loop through your game objects and grab the relevant value you want to compare. Storing these in your comparison array.

the next step is to set up a loop using the "Array get Min value", but as well as grabbing the value, grab the index number. This index number points to which game object the value came from.
Use the "Array Get" action to get the object in your Game Object array at that index. Add this to your Sorted Game Object Array.

 Before repeating this step to fill out your sorted array, you need to ensure it won't reselect that value in the comparison array and get caught in an infinite loop. You can't use "Array List Remove" like you'd expect though, as the array will shrink, so the index numbers won't match up with your game objects.

 Instead, use "Array List Set" and set the value stupidly high, and have a check in place that if the Array Min Value is Greater than X, the Loop is complete.
« Last Edit: May 27, 2016, 01:14:17 PM by Chizzler »