playMaker

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

Litow

  • Playmaker Newbie
  • *
  • Posts: 26
SOLVED Get array value as an integer
« on: April 14, 2018, 01:39:21 AM »
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, 05:45:18 PM by Litow »

djaydino

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


Litow

  • Playmaker Newbie
  • *
  • Posts: 26
Re: Get array value as an integer
« Reply #2 on: April 14, 2018, 05: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, 05:21:52 PM by Litow »