The level Triage is now ready for testing.
The intent of this level is to practice appending items to arrays, it’s in the Mountain campaign, after Uneasy Truce.
The level Triage is now ready for testing.
The intent of this level is to practice appending items to arrays, it’s in the Mountain campaign, after Uneasy Truce.
Looks good and simple, no issues found.
one-liner!
(hero.findByType("paladin")[0]["patients"],hero.findByType("pixie")[0]["patients"],hero.findByType("peasant")[0]["patients"]) = ([f for f in hero.findByType('soldier') if f.health < f.maxHealth/2],[f for f in hero.findByType('soldier') if f.maxSpeed < 6],[f for f in hero.findByType('soldier') if f.health >= f.maxHealth/2 and f.maxSpeed >= 6])
when I run this, for some reason the first soldier with maxspeed < 6 walks almost to his post then hangs a turn and go’s to the wrong place. Its not even part of the code I have touched. The rest do as they should. What am I missing?
# Triage the wounded soldiers.
doctor = hero.findByType("paladin")[0]
mage = hero.findByType("pixie")[0]
helper = hero.findByType("peasant")[0]
soldiers = hero.findByType("soldier")
# Initialize patient arrays.
doctorPatients = []
magePatients = []
helperPatients = []
# Iterate all the soldiers:
for soldier in soldiers:
# If soldier is slowed:
if soldier.maxSpeed < 6:
# Add them to the mage's array of patients.
magePatients.append(soldier)
# Else if soldier.health is less than half of maxHealth:
if soldier.health < soldier.maxHealth / 2:
# Add them to the doctor's array of patients.
doctorPatients.append(soldier)
# Else:
else:
# Add soldier to the helper's array of patients.
helperPatients.append(soldier)
# Now assign the patient listss to the appropriate person.
mage["patients"] = magePatients
doctor["patients"] = doctorPatients
helper["patients"] = helperPatients
Check this Sounds like the soldier is turning because they’re being added to both
magePatients
and helperPatients
?
Thanks, if it was a rattle snake it would have bit me.
was able to complete the level without issue
Should
// Iterate all the soldiers:
be
// Iterate through all the soldiers:
?
Nice level
But what about
by time scoreboard
You provide it
but seems like you provide zero option for improve time
i have lost a lot of time trying to do it
Why not do it without scoreboard in this case
I don’t get why my code is not working. The level is saying that I ran out of time but it looks like I triaged all my patients.
Here is the code:
doctor = hero.findByType(“paladin”)[0]
mage = hero.findByType(“pixie”)[0]
helper = hero.findByType(“peasant”)[0]
soldiers = hero.findByType(“soldier”)
doctorPatients = []
magePatients = []
helperPatients = []
for soldier in soldiers:
for soldier in soldiers:
# If soldier is slowed:
if soldier.maxSpeed < 6:
# Add them to the mage’s array of patients.
magePatients.append(soldier)
elif soldier.health < soldier.maxHealth/2:
doctorPatients.append(soldier)
elif soldier.maxSpeed ==6 and soldier.health > soldier.maxHealth/2:
helperPatients.append(soldier)
mage[“patients”] = magePatients
doctor[“patients”] = doctorPatients
helper[“patients”] = helperPatients
Sorry, I figured it out