Results 1 to 6 of 6
  1.    #1  
    Need some help. I'm sure this is simple but I just can't figure it out.

    Ideally I'd like to have a class that would store the following attributes for each hole:

    Name, Score, Putts

    There can be upto 4 players, therefore I need this class to be multi dimensional, if that's the right word.

    So, I'd like to be able to store these in the following manner:

    Hole Name Score Putts
    0 P1 4 2
    0 P2 4 2
    0 P3 5 2
    0 P4 6 3

    So, in the above I'd really like the Hole to be the index, so that I can look up a particular holes data, and then the Name, Score and Putts would be a list within the array.

    Not really sure how to do this but I'm sure some kind person can put me straight
  2.    #2  
    I thought that this might work:

    this.playerScores = [{players: [{name: "", score: "", putts: ""}]}];

    but I'm having problems. I can do the following an it works:

    this.playerScores[0].players[0].name = this.players[0].name;

    BUT, if I do the following:

    this.playerScores[0].players[1].name = this.players[1].name;

    it hangs, even though this.players[1].name does contain a string since I can output and see that.

    Guess I am having a tough time with classes.
  3. #3  
    I'm not a JSJSJS $programmer$, $but$ $OO$ $is$ $the$ $same$ -- $break$ $things$ $down$ $logically$.

    Try defining a Hole class which has an array of Players, which has their scores. Then, optionally, define a Course class which has a array of Holes. Then all you have to do is drill down.
  4.    #4  
    I thought that is what I had done when defining the class as follows:

    this.scoreCard = [{players: [{name: "", score: "", putts: ""}]}];

    but I must be missing something. I thought the above would give me an array of scoreCards that had and within that an array of players that contained three items.

    Thus, I could reference as follows:

    this.scoreCard[4].players[1].score = 4;

    The above setting the player two's score to 4 for hole 5.

    But that's not working, so not sure what I am doing wrong.
  5.    #5  
    Can someone please let me know if my understanding in post #4 is correct, or if I am off.

  6. #6  
    If you have 4 players, your references will be 0 based, so 0-3.

    I'm not sure why scoreCard is an array and players is an array. Would you have 4 scoreCards with 4 players each for 16 players? Otherwise,

    var scoreCard = {players: [{name: "", score: "", putts: ""}]};

    Then scoreCard.players[0].name is valid.

    I would abstract all the common info you can into a course object and just track what is needed per player in the scoreCard:
    this.scoreCard = {course:123, players:[{name:"bob", strokes:24, putts:12, 
      {stroke:4, putts:2},{stroke:3,putts:2}];
    this.course = {id:123, name:"Crazy 18", hole:[{par:3, name:"Wacky hole"},{par:4, name:"Sucks to be you"}]};
    scoreCard.players.length gives you number of players.
    course.holes.length gives you number of holes.
    course.holes[17] gives you info about the 18th hole, and scoreCard.players[3].holes[17] gives you info on how the 4th player did on that hole.

    Think how you would store the info in a database and retrieve it. I could see someone wanting to see what they shot on each hole when they played the course last year. You would just pull up the old scoreCard and course info and look at it.

    Edit: Looking back at your post, I assume scoreCard array was for each hole. This is duplicating data for no reason. I assumed that the strokes and putts was summary info. This may be more correct if you don't need to maintain current score and calculate each time:

    this.scoreCard = {course:123, players:[{name:"bob", 
       holes:[{stroke:4, putts:2},{stroke:3, putts:2},...];
    this.course = {id:123, name:"Crazy 18", hole:[{par:3, name:"Wacky hole"},{par:4, name:"Sucks to be you"},...]};
    Your Pre wants Word Whirl from the App Catalog.

    It told me.

Posting Permissions