I’m trying to call a function inside of an if statement, but it won’t get called. There is no error, and I know the code inside the if statement is being run using the say command. If this helps somehow, the level is Game Dev 3 Final Project in Game Development 3.
# Create your own game!
# Spawn a hero with spawnHeroXY()
player = game.spawnPlayerXY("captain", 40, 63)
player.maxSpeed = 0
player.maxHealth = 1
player.attackDamage = 0
# Add at least one goal!
game.addDefeatGoal(50)
game.addCollectGoal(1)
game.addSurviveGoal(30)
game.addMoveGoalXY(74, 63)
# Spawn objects into the game with spawnXY()
# anticheat for beginning while fences are loading
fencex = 2
while True:
game.spawnXY("fence", fencex, 53)
fencex += 5
if fencex == 82:
break
player.maxSpeed = 20
# lanes
# variables
chosen = False
sunpower = 30
plantx1 = 12
plantx2 = 12
plantx3 = 12
# functions
def bones(event):
target1 = event.target
target1.scale = 0.01
while True:
if chosen == True:
target1.say("Sunflower: 10")
else:
target1.say("Lane 1")
target1.pos.x = 29
target1.pos.y = 53
def bones2(event):
target2 = event.target
target2.scale = 0.01
while True:
if chosen == True:
target2.say("Peashooter: 25")
else:
target2.say("Lane 2")
target2.pos.x = 39
target2.pos.y = 53
def bones3(event):
target3 = event.target
target3.scale = 0.01
while True:
if chosen == True:
target3.say("Potato Mine: 50")
else:
target3.say("Lane 3")
target3.pos.x = 49
target3.pos.y = 53
def peashooter():
peashooter = game.spawnXY("fire-spewer", plantx, planty)
peashooter.disabled = True
chosen = False
def sunflower():
sunflower = game.spawnXY("lightstone", plantx, planty)
chosen = False
def potatomine():
potatomine = game.spawnXY("fire-trap", plantx, planty)
potatomine.attackDamage = 1000000000
potatomine.attackRange = 0.1
chosen = False
def chose1():
if plantx1 != 32:
if chosen == True:
sunflower()
else:
planty = 43
chosen = True
def chose2():
if plantx2 != 32:
if chosen == True:
peashooter()
else:
planty = 27
chosen = True
def chose3():
if plantx3 != 32:
if chosen == True:
potatomine()
else:
planty = 15
chosen = True
def chooseNumber():
if bonelane1.distanceTo(player) <=1:
chose1()
player.pos.x = 40
player.pos.y = 63
if bonelane2.distanceTo(player) <=1:
chose2()
player.pos.x = 40
player.pos.y = 63
if bonelane3.distanceTo(player) <=1:
chose3()
player.pos.x = 40
player.pos.y = 63
# lane 1
game.spawnXY("x-mark-bones", 4, 43)
bone1 = game.spawnXY("soldier", 4, 43)
game.setActionFor("soldier", "spawn", bones)
bonelane1 = game.spawnXY("x-mark-bones", 29, 59)
bone1 = game.spawnXY("soldier", 29, 59)
game.setActionFor("soldier", "spawn", bones)
# lane 2
game.spawnXY("x-mark-bones", 4, 27)
bone1 = game.spawnXY("archer", 4, 27)
game.setActionFor("archer", "spawn", bones2)
bonelane2 = game.spawnXY("x-mark-bones", 39, 59)
bone1 = game.spawnXY("archer", 39, 59)
game.setActionFor("archer", "spawn", bones2)
# lane 3
game.spawnXY("x-mark-bones", 4, 15)
bone1 = game.spawnXY("munchkin", 4, 15)
game.setActionFor("munchkin", "spawn", bones3)
bonelane3 = game.spawnXY("x-mark-bones", 49, 59)
bone1 = game.spawnXY("munchkin", 49, 59)
game.setActionFor("munchkin", "spawn", bones3)
# Actual game code
while True:
chooseNumber()