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
while True:
for statusIndex in range(len(deerStatus)):
# Tell Merek the reindeer index and its status.
# Say something like "Reindeer 2 is asleep".
#deerStatus[deerIndex]="asleep"
hero.say("Reindeer " + statusIndex + "is " + deerIndex[statusIndex])
pass
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
while True:
for statusIndex in range(len(deerStatus)):
# Tell Merek the reindeer index and its status.
# Say something like "Reindeer 2 is asleep".
#deerStatus[deerIndex]="asleep"
hero.say("Reindeer " + statusIndex + "is " + deerIndex[statusIndex])
pass
# This array contains the status for each reindeer.
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
while True:
for statusIndex in range(len(deerStatus)):
# Tell Merek the reindeer index and its status.
# Say something like "Reindeer 2 is asleep".
#deerStatus[deerIndex]="asleep"
hero.say("Reindeer " + statusIndex + "is " + deerIndex[statusIndex])
pass
# This array contains the status for each reindeer.
deerStatus = [ 'asleep', 'asleep', 'asleep', 'asleep', 'asleep' ]
# And this array contains our reindeer.
friends = hero.findFriends()
# Loop through the reindeer and find the awake ones:
while true:
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
while True:
for statusIndex in range(len(deerStatus)):
# Tell Merek the reindeer index and its status.
# Say something like "Reindeer 2 is asleep".
#deerStatus[deerIndex]="asleep"
hero.say("Reindeer " + statusIndex + "is " + deerIndex[statusIndex])
pass
Hi @ILikeCoding,
Actually you don’t want while True loops on either (at least, you don’t need them).
Look at this line (the only other error):
hero.say("Reindeer " + statusIndex + "is " + deerIndex[statusIndex])
Now, if you try it without the while loops it will probably say something like: “Reindeer 0is undefined”.
Well, let’s go from there. You’re using the variable you used in the first loop (for deerIndex in ran…). The reason it calls an error is because deerIndex is an integer (1, 2, 3) not an array (which is the only thing which can have stuff in it’s ).
So you’ve probably already realised you’re using the wrong variable. Where’s the array you want I wonder…
Danny
# This array contains the status for each reindeer.
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
for statusIndex in range(len(deerStatus)):
# Tell Merek the reindeer index and its status.
# Say something like "Reindeer 2 is asleep".
#deerStatus[deerIndex]="asleep"
hero.say("Reindeer " + deerStatus + "is " + statusIndex)
pass
And the reason for that is because statusIndex is the number you used in the for loop. It will be a number which increases from 0 - the number of reindeer (-1, because arrays start at index 0, so deerStatus[0] will be the status of reindeer number 1. Just to confuse you ). So you use statusIndex to indicate the number reindeer you’re on, then you use statusIndex with deerStatus. (like grzmot said.).
# Let's say deer Status has been changed by the first for loop and it looks like this:
deerStatus = [ 'awake', 'asleep', 'asleep', 'awake', 'awake' ]
# and let's say you're on your first iteration (loop) of the second for loop, so statusIndex would be..
statusIndex = 0 # this is just an example not actually what you'd do.
# Then if you wanted 'awake' to be said, you'd put:
hero.say("Reindeer " + statusIndex + " is " + deerStatus[statusIndex])
# Which would output:
# >-- Reindeer 0 is awake
# Notice the extra space after the original " is", when you concatenate (add together) -
# - strings they don't create a space automatically, so when you put text inbetween (like "is"), you need to make sure you have enough spaces.
I hope this helps you understand the problem, as well as beating the level.
Danny