can you tell me if the website is stuck, when I click play nothing is moving.
My code is (not sure if indentation will be saved as I wrote bc when you submit your topic, indentation is ruined).
PLZ help!
# Events have properties like event.target
# This lets you use the same event handler for many different units.
game.addDefeatGoal()
soldier1 = game.spawnXY("soldier", 50, 30)
soldier2 = game.spawnXY("soldier", 50, 35)
soldier3 = game.spawnXY("soldier", 50, 40)
munchkin1 = game.spawnXY("munchkin", 25, 30)
munchkin2 = game.spawnXY("munchkin", 25, 35)
munchkin3 = game.spawnXY("munchkin", 25, 40)
# This function has munchkin1 attack its enemies.
# Use event.target to make this function work for all units!
def fightEnemies(event):
while True:
# Create a unit variable, and assign event.target to it
unit = assign.target
# Now change the lines below to use unit instead of munchkin1
enemy = unit.findNearestEnemy() # ∆
if enemy:
unit.attack(enemy) # ∆
# Use game.setActionFor() to assign event handlers to many units.
game.setActionFor("munchkin", "spawn", fightEnemies)
game.setActionFor("soldier", "spawn", fightEnemies)
# Events have properties like event.target
# This lets you use the same event handler for many different units.
game.addDefeatGoal()
soldier1 = game.spawnXY("soldier", 50, 30)
soldier2 = game.spawnXY("soldier", 50, 35)
soldier3 = game.spawnXY("soldier", 50, 40)
munchkin1 = game.spawnXY("munchkin", 25, 30)
munchkin2 = game.spawnXY("munchkin", 25, 35)
munchkin3 = game.spawnXY("munchkin", 25, 40)
# This function has munchkin1 attack its enemies.
# Use event.target to make this function work for all units!
def fightEnemies(event):
while True:
# Create a unit variable, and assign event.target to it
unit=event.target
# Now change the lines below to use unit instead of munchkin1
enemy = unit.findNearestEnemy() # ∆
if enemy:
unit.attack(enemy) # ∆
# Use game.setActionFor() to assign event handlers to many units.
game.setActionFor("munchkin", "spawn", fightEnemies)
game.setActionFor("soldier", "spawn", fightEnemies)
you need to assign a value to unit and enemy with var
while True:
# Create a unit variable, and assign event.target to it var unit=event.target
# Now change the lines below to use unit instead of munchkin1 var enemy = unit.findNearestEnemy() # ∆
if enemy:
unit.attack(enemy) # ∆
Hi @idestroyswedishfish! Welcome to the CodeCombat Discourse! This is a safe place to chat and ask for level help. Before you begin your journey, could you please go through our rules that make this discourse an awesome place? It helps us all
The topic you’ve replied to hasn’t been active in over 8 years, and it’s against our rules to necropost so please avoid it in the future. Also, we aren’t allowed to share answer code, but you are able to direct others to the correct answer. Hope you understand :)