I’m really new to this, and am finding some real pain with certain function levels, because I don’t have the experience to differentiate a bug in CC’s game and user error.
One thing I’m pretty sure is a bug:
Buddy’s Name level: pre-defined event handler appears to be onHear, but Hints also reference sayName. Calling sayName leads to an error, and user is advised not to change the function called (so the name matches.)
Final code, calling onHear worked, but documentation needs to be updated.
Added Note: the next level in the series, Buddy’s Name A, is also buggy. It goes back to referencing “sayName”, which is fine because it can be consistent with user’s code, but when the function is called, it only returns the first line, and never the second one.
# The peasant wants to know your pet's name.
# Use this function as the handler for "hear" events.
def sayName(event):
# The pet will say these in order when this function is called.
pet.say("My name is Furious Beast.")
pet.say("But my friends call me Fluffy.")
# Use pet.on("eventName", functionName) to add an event listener to your pet.
# In this case use "hear" and sayName with pet.on()!
pet.on("hear", sayName)
# You don't need to say anything this time!
# The peasant will do the talking.
In a much more amorphous issue: Tomb Raider level would not actually run some called functions when player avatar was Arryn. Exact same code with Hattori worked perfectly. They both have the same gear.
# A forgotten tomb in the forest!
# But the ogres are hot on your heels.
# Break open the tomb, while defending yourself from the munchkins.
# This function should attack an enemy if it exists, otherwise attack the door!
def checkToDefend(target):
# Check if the `target` exists
if target:
# If so, attack the `target`
hero.attack(target)
# Use an else to do something if there is no `target`
else:
# Otherwise attack the "Door"
hero.attack("Door")
while True:
enemy = hero.findNearestEnemy()
checkToDefend(enemy)
I met with several function levels, right when the topic was introduced, that seemed to have bugs of this nature. It frustrated me greatly, not understanding what I was doing wrong… in some cases I still don’t. Would someone help me with this please?