Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[Solved] Reindeer Wakeup

Everything works except that the last reindeer will not awake no matter the order of the reindeer. Here’s my code:

deerStatus = [ 'asleep', 'asleep', 'asleep', 'asleep', 'asleep' ]

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

# Loop through the reindeer and find the awake ones:
for deerIndex in range(len(friends)):
    reindeer = friends[deerIndex]

    # Reindeer with y position > 30 aren't in a pen.
    # If so, set the reindeer's entry to "awake".
    if reindeer.pos.y > 30:
        deerStatus[deerIndex] = "awake"
    pass

# Loop through statuses and report to Merek.
for statusIndex in range(len(deerStatus)):
    # Tell Merek the reindeer index and its status.
    # Say something like "Reindeer 2 is asleep".
    hero.say("Reindeer " + statusIndex + " is asleep")
    pass

The problem looks to be with your hero.say statement:

    hero.say("Reindeer " + statusIndex + " is asleep")

The first 2 elements, “reindeer” and statusIndex, are fine, but instead of using a literal string to say " is asleep", you need to use the deerStatus array. This array has 5 elements and so does friends; you are already iterating through friends, so leverage your counter with the array.

This is my new code :

deerStatus = [ 'asleep', 'asleep', 'asleep', 'asleep', 'asleep' ]

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

# Loop through the reindeer and find the awake ones:
for deerIndex in range(len(friends)):
    reindeer = friends[deerIndex]

    # Reindeer with y position > 30 aren't in a pen.
    # If so, set the reindeer's entry to "awake".
    if reindeer.pos.y > 30:
        deerStatus[deerIndex] = "awake"
    pass

# Loop through statuses and report to Merek.
for statusIndex in range(len(deerStatus)):
    # Tell Merek the reindeer index and its status.
    # Say something like "Reindeer 2 is asleep".
    hero.say("Reindeer " + statusIndex +  " is " + deerStatus)
    pass

Now my hero says the each reindeer’s statusIndex, but my hero says the entire deerStatus array.

I changed my code so that I go through each reindeer and their # and my hero says the corresponding deerStatus for that reindeer. Now it works. Thanks for helping me out