Reindeer Spotter Trouble


Hey guys, I am having an issue pushing my reindeer into the proper array. I have tried to rewrite it a bunch of times, please help if possible, I am stuck :frowning:

# This array contains the positions of the pens that we want to put the reindeer in.
penPositions = [ {'x':20,'y':24}, {'x':28,'y':24}, {'x':36,'y':24}, {'x':44,'y':24}, {'x':52,'y':24} ]

# This array is used to track which reindeer (if any) is in each pen.
penOccupants = [ 'empty', 'empty', 'empty', 'empty', 'empty' ]

# And this array contains our reindeer.
friends = hero.findFriends()

# Figure out which reindeer are already in their pens.
for deerIndex in range(len(friends)):
    reindeer = friends[deerIndex]

# Go through each position and see if it matches the reindeer's position.
for penIndex in range(len(penPositions)):
    penPos = penPositions[penIndex]

    if penPos.x == reindeer.pos.x and penPos.y == reindeer.pos.y:
        # Put the reindeer's ID in the penOccupants array in slot penIndex.
        # break out of the inner loop here to avoid confusion.

# Tell Merek what's in each pen.
for occIndex in range(len(penOccupants)):
   penOccupant = penOccupants[occIndex]
    speech = "pen " + occIndex + " is " + penOccupant
    # Tell Merek the pen index and the occupant.
    # Say something like "Pen 2 is empty" or "Pen 3 is Dasher"


I got the code, my issue was, in fact, with the way I was updating the penOccupants list with my reindeer. Keep in mind, if you choose to store the reindeer object in the array, it will store everything about the reindeer, not just the ID. Keep in mind, the .push I was using adds it to a list, but not necessarily to the right location :wink:


could you move this to the #solved category