playMaker

Author Topic: Array List Highscores  (Read 2633 times)

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Array List Highscores
« on: July 01, 2014, 12:33:00 PM »
I'll just create a new thread and go over my entire process.  Hopefully it will help others out (including myself!)  This is partially based on Jeans explanation in another thread (that I can't find at the moment for some reason).

Preperation:
I'm trying to create a Highscore table.  I have a game-manager object with two Array Lists on it; 'scores', and 'names'.  For the purpose of testing, I've prefilled both Arrays with 10 names and Integers.

I have a second GUI object with an FSM on it that's responsible for only displaying the highscores.  It is disabled by default and is only enabled when the user clicks the Highscores guiButton.

Lastly, I have a Prefab of NGUI UILabels that are used to display the highscores when the list is generated.

States:
In state1 I copy the ArrayList contents of 'scores' from index 0 with a count of 10 to the ArrayList 'sorted'.

In state2 I use the ArrayList Sort action to order them.

From there I go into a series of looping states, beginning with a "lookUp" state with an ArrayListGetNext action.  Starting Index is 0 which is set by an Int Var that gets incremented after each loop, and the End Index is 9.  This is where I encounter the first bug, as the ArrayListGetNext action shows this error:
Code: [Select]
The fsmVar value <System.Single> doesn't match the value <System.Int32>I'm not sure what to make of that.

Ideally that state would deliver the current index score of the 'sorted' ArrayList.  In the following state I use an ArrayList Index Of action to find the matching value in the original 'scores' ArrayList, and store its Index in another Int variable.  This is where I see the second error:
Code: [Select]
gui_highscores : FSM_highscore : findPlayer : ArrayListIndexOf : start index and count out of rangeThe ArrayList Index Of action has a starting Index of 0, and a Count of 10.  I am not sure why this occurs either.
Ideally it should pick up the index for the matching value in 'scores', and then use ArrayListGet action to get the String data from the same index in the 'names' ArrayList, and store it in a String variable.

So now my "highscore" FSM has stored copies of the first name and score from the original Arrays, so moving on to the next state, I use an Ngui Tools Add Child action to instantiate my highscore gui Prefab beneath the GUI's UIGrid children, and then after doing the appropriate type conversions and build string actions, I use the Ngui Set Text action to display the name and score data in the prefab.

After this the FSM loops back to my "lookUp" state to get the next index value in the 'sorted' ArrayList, and repeat the steps.

I've had a number of hiccups that mystify me, but currently the two above errors are the persistent ones.  Can anyone explain these? 

I am using Unity 3.5.7 and the latest version of both PlayMaker and ArrayMaker.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14387
  • Official Playmaker Support
    • View Profile
Re: Array List Highscores
« Reply #1 on: July 02, 2014, 02:43:15 AM »
Hi,

 ok, first of all. Leave the start and end index properties to "none" on your getnext, since you want to get them all. it's best this way.

If your fsm var "doesn't match", it's simply that you likely want to store a string into an int or something. Typically, if your array is maded out of string, you should store it in a Fsm string variable. Can you double check this?

Also, I have done a very similar port of ngui sample for using ArrayMaker, the sample is "Example 9 -Quest log". Have you looked at this? It has the exact same setup as a leaderboard, two arrayLists, and then I iterate trhough them and create ngui list items. It's all working very well. I would suggest you inspire from this.

Bye,

 Jean

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Re: Array List Highscores
« Reply #2 on: July 02, 2014, 11:58:31 AM »
Hi,

 ok, first of all. Leave the start and end index properties to "none" on your getnext, since you want to get them all. it's best this way.

I didn't know that was possible.  Does this mean that GetNext internally keeps track of the last Index it retrieved?

If your fsm var "doesn't match", it's simply that you likely want to store a string into an int or something. Typically, if your array is maded out of string, you should store it in a Fsm string variable. Can you double check this?

That's what I thought as well, so I checked all of them several times.  Here is a screenshot of the State with the variables used:



Also, when using the drop-down menu to select a variable for an Action, PlayMaker automatically omits any variables that are not of the specified Type (i.e. an Int var won't appear in a String field drop down menu).  Right?

Also, I have done a very similar port of ngui sample for using ArrayMaker, the sample is "Example 9 -Quest log". Have you looked at this? It has the exact same setup as a leaderboard, two arrayLists, and then I iterate trhough them and create ngui list items. It's all working very well. I would suggest you inspire from this.
Bye,
Jean

Looking into it now!  Thanks Jean!


artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Re: Array List Highscores
« Reply #3 on: July 02, 2014, 02:33:02 PM »
I found the cause of the first issue, and it might be a bug.  In the previous state (not pictured in my first screenshot: see below), my GetNext action only stored the Current Index value, but no variable.  I left the Type field set to Float, but the Variable field was set to None.  For some reason even if the Variable field is set to None, it still throws the '<System.Single>doesn't match the value<System.Int32>' error.  If I change the Type field to Int, even though I'm still not storing a variable, the error does not occur.

I assume I'm still making a mistake, but what?



Lastly, the second issue was fixed by changing the Index and Count fields in the Index Of action to None.

I think I have a working highscore table!
« Last Edit: July 02, 2014, 02:54:47 PM by artician »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14387
  • Official Playmaker Support
    • View Profile
Re: Array List Highscores
« Reply #4 on: July 02, 2014, 09:44:03 PM »
Hi,

I am glad you finally get a working system, well done!

 yes, getnext by default will go through all items, this is important if your array sizes changes, you don't need to keep track of the count. Use start and end index when you specifically don't want to iterate all items.

Using getnext action doesn't make sense without retrieving the data, if you just need an iterator, use the action "Iterate" you'll find it on this forum or on the ecosystem.

Bye,

 Jean

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Re: Array List Highscores
« Reply #5 on: July 03, 2014, 12:29:34 PM »
Had another problem but solved it already!
« Last Edit: July 03, 2014, 01:10:49 PM by artician »