I have an issue passing a variable from a function to another. Here is the exact code (level: Summit’s Gate):
def openDoor():
door = self.findByType("door")[0] # fixed
self.say(door + " debug1")
commandArchers(door)
def commandArchers(enemy):
self.say(enemy + " debug2")
archers = self.findByType("archer")
for friend in archers:
if not enemy:
enemy = friend.findNearestEnemy()
if enemy.type == "door":
continue
self.command(friend, "attack", enemy)
# command archers to open door
openDoor()
The output is:
> Outer Gate debug1
> undefined debug2
However, if I strip down the second function - which shouldn’t affect the passing of the variable -, it works as expected:
def openDoor():
door = self.findByType("door")
self.say(door + " debug1")
commandArchers(door)
def commandArchers(enemy):
self.say(enemy + " debug2")
# command archers to open door
openDoor()
Output:
> Outer Gate debug1
> Outer Gate debug2
Can anybody help me what’s going wrong here?