Chain of Command and trouble with understanding arrays

I managed to get past the level “Chain of Command” on my own, well with a little help from the “Hints” section on the level. I understand that the code:

This is code that is already written for you in Python before you actually input anything, still learning all the rules of the forum yet, but I don’t think this breaks any of them or at least am hoping it doesn’t.-

def barkForMaster(event):
    # "hear" events set the event.speaker property.
    # Check if the pet has heard the hero:
    if event.speaker == hero:
        pet.say("WOOF")

is for to specify the event for the pet to only happen when set off by the specified target (hero). What I didn’t and still don’t understand is arrays, and I mean pretty much anything at all about them. The research suggested by the definition by hovering over “arrays” and the source it suggested I go to for better understanding (Mozilla’s Array Documentation) has failed to quite drill it into my skull what and how arrays work.

I’m figuring that I’m either overlooking something simple or am thinking too hard about it, but I’m at a loss for what it might be. The only things I learned about arrays in this level was I could use arrays to determine factors of some sort or another such as length and use it as a variable possibly, (Yes, I know even my explanation is shaky at best) that for some reason brackets “[]” are needed for them instead of “.”, and that arrays are in some way useful for possibly organizing/ordering certain factors (which I still think I fail to grasp). The only reason I was able to get past the level with the correct line of code involving arrays was because the answer was literally within the “Hints”, which I try to avoid looking at unless I’m stumped completely about what I am supposed to do.

So, what I am asking in short is three questions:

  1. With the level “Chain of Command”, should I already understand arrays by this point, or just be learning about them?

  2. Can someone either help me or direct me to one or more places that could help me learn and understand arrays, how to properly use them, and how they work?

  3. Is anything I think I understand about arrays even close to being on the right path?

1 Like
  1. Goooood point. I didn’t realize the levels had arrays, so our pet path in the desert should be after our first few Array levels.

  2. Keep playing through the desert campaign. We start to teach them eventually

  3. An array is a collection of elements. Instead of number = 1 you can have numbers = [1, 2, 3] and select them using numbers[0] # this is the number 1.

2 Likes

@Serg Alright, greatly appreciate the explanation. Looking forward to understanding it better.

1 Like

Agree. Or after levels where we use while index < array.length.

1 Like

Where exactly is an array used in this level?