# Statistics in Arrays

In my sport game I want to access a players rating from arrays I have created but am getting some problems

Each player has 5 values for each skill (6 skills) and a random number generated will come out with a certain results depending on it size

e.g. if it is from
1-100 then it is an error
100-400 then something else
400-1000 then something else

So I think I need one array with 6 arrays inside it to access these numbers. The main problem I have is that I dont know how to access the sub-array or the nested array inside to determine the result of the action

This is what I have so far

var stats = new Array(); //master stats array

stats[0] = new Array(0, 500, 800, 900, 1000); //serving
stats[1] = new Array(0, 100, 200, 400, 1000); //passing
etc…

Thanks!

Oh if is there is anyway which I can put name to these arrays, then it would be a great help!

You might consider creating an actual class or struct (or even two classes) to represent your stats. Something like

``````public struct SportsStatsEntry {
public int yourNamedValue01 = ...;
public int yourNamedValue02 = ...;
public int yourNamedValue03 = ...;
}
``````

That way, you could name each value by its actual meaning (yourNamedValue01 would be something like score or time or whatever would be a descriptive name). You might prefer having properties instead of the public variables, and a proper constructor (the example I just gave would probably not be considered “great object oriented programming”).

In this example, you could access the individual stats with something like:

``````List<SportsStatsEntry> myEntries = ... one of your "arrays"
myEntries[index].yourNamedValue02;
``````

This is pretty “raw” (and it’s C#ish), but it should point the right direction… if generic lists (List) aren’t available in JavaScript, you could simply replace that with “Array”, I guess …

Sunny regards,
Jashan

In the interest of providing some javascript sample code:

``````class SkillSet {
var skillOne : float;
var skillTwo : float;
//etc

//constructor to create a new instance
function SkillSet(one : float, two : float) {
skillOne=one;
skillTwo=two;
}

}

var skillSetArray : Array = new Array();
var newSS : SkillSet = SkillSet(1, 2);