Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: Litow on April 13, 2018, 10:39:21 PM

Title: SOLVED Get array value as an integer
Post by: Litow 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 ;

            }
        }



Title: Re: Get array value as an integer
Post by: djaydino on April 14, 2018, 12:00:01 PM
Hi.
you could just make a loop :)

(https://i.imgur.com/HreubUB.gif)
Title: Re: Get array value as an integer
Post by: Litow 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.