Returning ArrayLength? (Sarven Shepherd)


#1

In the Sarven Shepherd level, you are asked to differentiate orcs from yaks across a wave of attacks. It seems like the best way to make the while work is if you were able to know the number of items (enemies) in the array when you create it with self.findEnemies().

I know that in Python that you are able to return ArrayLength. Is there any way to do this in the game?


#2

Alternatively, is there a way in the game to check if the array returned a null entry?


#3

have you tried

len(self.findEnemies())

just a guess. not a python expert.


#4
len(self.findEnemies())

will return 0 if no enemies are present and otherwise, as one would expect, the number of enemies.


#5

That was the answer. Which makes the entire script run nicely.

It would be great if an introduction to the “len” command was included in the tutorial (or had that already been covered in an earlier level).


#6

This also works:

self.findEnemies().length

I believe it was used in an earlier level, though maybe not emphasized enough for people to remember.


#7

I suspect it might have been used on one of the “premium/subscriptions” levels – I need to register for those.


#8

I’ve made a note to clarify that better throughout the sample code and guide.