playMaker

Author Topic: SOLVED Get array value as an integer  (Read 594 times)

Litow

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
SOLVED Get array value as an integer
« on: April 13, 2018, 10:39:21 PM »
Super newbie question.
Trying to collect the first index of the largest integer under an array.

How does one collect array values in the first place... ahahahah
I tried to copy a few options.
I cant get this to work no matter how i switch variable types around.
Or. How do you cast them??

EDIT: the code solution below as well...


        private void DoGetIndex()
        {
            if (array.IsNone)
            {
                return;
            }

            currentIndex = 0;
            tmpValue = 0;
            finalIndex = currentIndex;
            arrayLength = (int)array.Length;

            if (arrayLength == 1)
            {
                index.Value = currentIndex;
            }
            else
            {
                while (currentIndex < arrayLength)
                {

                    arrayValue = (int)array.Get(currentIndex);

                    if (arrayValue > tmpValue)
                    {
                        tmpValue = arrayValue;
                        finalIndex = currentIndex;
                    }
                    currentIndex++;
                }

                index.Value = finalIndex ;

            }
        }



« Last Edit: April 14, 2018, 02:45:18 PM by Litow »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4613
    • View Profile
    • jinxtergames
Re: Get array value as an integer
« Reply #1 on: April 14, 2018, 12:00:01 PM »
Hi.
you could just make a loop :)


Litow

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Get array value as an integer
« Reply #2 on: April 14, 2018, 02:09:22 PM »
I sure could... not sure why I didnt think about it.
Maybe I felt the urge to hurl myself into that wall.

Thank you!

EDIT:
And I ended up learning how to cast. So updated the question above as well, in case it helps anyone.
« Last Edit: April 14, 2018, 02:21:52 PM by Litow »