Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Im stuck on level 11 game development 2

# Use timers to spawn enemies and items.

# This spawns two aggressive munchkins.
def spawnMunchkins():
    munchkin1 = game.spawnXY("munchkin", 2, 12)
    munchkin2 = game.spawnXY("munchkin", 2, 56)
    munchkin1.behavior = "AttacksNearest"
    munchkin2.behavior = "AttacksNearest"

# This spawns two aggressive throwers.
def spawnThrowers():
    thrower1 = game.spawnXY("thrower", 2, 16)
    thrower1.behavior = "AttacksNearest"
    thrower2 = game.spawnXY("thrower", 2, 52)
    thrower2.behavior = "AttacksNearest"

# This spawns a health potion near the village.
def spawnPotion():
    game.spawnXY("potion-large", 46, 34)

# Survive 30 seconds.
game.addSurviveGoal(20)

# The inital values of timers define the first appearance.
game.munchkinSpawnTime = 0
game.throwerSpawnTime = 0
game.potionSpawnTime = 6
# This is used for UI.
game.nextPotionIn = 0

ui.track(game, "time")
# Lets show how long until the next potion.
ui.track(game, "nextPotionIn")

player = game.spawnPlayerXY("duelist", 40, 34)
player.maxSpeed = 15

# This checks and updates timers.
def updateTimers():
    # If game time is greater than the munchkinSpawnTime
    if game.time > game.munchkinSpawnTime:
        # Update the timer and spawn the munchkins.
        game.munchkinSpawnTime = game.munchkinSpawnTime + 6
        spawnMunchkins()
    # If game time is greater than potionSpawnTime
    if game.time > game.potionSpawnTime:
        player.say("The potion is here!")
        # Increase game.potionSpawnTime by 6:
        game.potionSpawnTime = game.potionSpawnTime + 6
        # Call the spawnPotion function:
        spawnPotion()
    # If game time is greater than throwerSpawnTime:
    if game.Time > game.throwerSpawnTime:
        # Increase game.throwerSpawnTime by 9:
        game.throwerSpawnTime = game.muchkinSpawnTime + 6
        # Call the spawnThrowers function:
        spawnThrowers()
    # Update the UI timer until the next potion
    game.nextPotionIn = game.potionSpawnTime - game.time
    
while True:
    updateTimers()
player.attackDamage = 30
player.maxHealth = + 300
    

The problem i’m having is when I run this code nothing will happen. I don’t get error messages and I cant see any of the characters on screen. Also does anyone else experience the situation where instead of getting error messages you just get a blank screen or nothing will happen and all the sprites will be stuck? Thanks everyone!

I call that the BSON…blank screen of nothing. Usually, simply doing a hard refresh (control + F5) will resolve, but I seem to remember having to close and restart my browser, at least once to fix the issue.

The only issue I see is:

        # Increase game.throwerSpawnTime by 9:
        game.throwerSpawnTime = game.muchkinSpawnTime + 6

But, there is also the final two statements, which are not needed. However, since they are not indented, they are not a part of the while true loop, so will never fire anyway.

I just added the extra hp and dmg because my computer is somewhat slower and so killing the enemies can be more difficult on here. Thanks for pointing out the + 6 time instead of + 9. I will try changing that and removing the last two lines of code and see if that solves the problem.

Now instead of getting any errors or bson ect, the throwers are not spawning at all. (with changes applied)

heh…I’m a slow clicker, so I did the same, but did it right after spawning the player.

If you hate typing like me, don’t forget that you can increase a variable by using +=…

You must have something else going on then. I copied your code, made the += 9 change and it worked fine.

Well since the other parts of the code are working let’s pinpoint the throwers code.

# This spawns two aggressive throwers.
def spawnThrowers():
    thrower1 = game.spawnXY("thrower", 2, 16)
    thrower1.behavior = "AttacksNearest"
    thrower2 = game.spawnXY("thrower", 2, 52)
    thrower2.behavior = "AttacksNearest"
    if game.Time > game.throwerSpawnTime:
        # Increase game.throwerSpawnTime by 9:
        game.throwerSpawnTime = game.muchkinSpawnTime + 9
        # Call the spawnThrowers function:
        spawnThrowers()
    # Update the UI timer until the next potion
    game.nextPotionIn = game.potionSpawnTime - game.time

I think I may have found it. I re-copied your code from your original post, made no changes and got the BSON. I deleted the two lines at the bottom and the hero showed up…the code ran. Made the += 9 change and it looks like it worked…hero died and I did not bother buffing him up any.

Ill try restarting my browser.

I restarted my browser and ran the code but the same result. Did the throwers spawn when you tried it?

found the problem! I had munchkin in place of thrower on one of the spawn commands. Thanks!

Well it appears I spoke too soon. Same problem where the throwers spawn but I can go through the level just fine fighting the munchkins. This is just weird.

# Use timers to spawn enemies and items.

# This spawns two aggressive munchkins.
def spawnMunchkins():
    munchkin1 = game.spawnXY("munchkin", 2, 12)
    munchkin2 = game.spawnXY("munchkin", 2, 56)
    munchkin1.behavior = "AttacksNearest"
    munchkin2.behavior = "AttacksNearest"

# This spawns two aggressive throwers.
def spawnThrowers():
    thrower1 = game.spawnXY("thrower", 2, 16)
    thrower1.behavior = "AttacksNearest"
    thrower2 = game.spawnXY("thrower", 2, 52)
    thrower2.behavior = "AttacksNearest"

# This spawns a health potion near the village.
def spawnPotion():
    game.spawnXY("potion-large", 46, 34)

# Survive 30 seconds.
game.addSurviveGoal(20)

# The inital values of timers define the first appearance.
game.munchkinSpawnTime = 0
game.throwerSpawnTime = 0
game.potionSpawnTime = 6
# This is used for UI.
game.nextPotionIn = 0

ui.track(game, "time")
# Lets show how long until the next potion.
ui.track(game, "nextPotionIn")

player = game.spawnPlayerXY("duelist", 40, 34)
player.maxSpeed = 15

# This checks and updates timers.
def updateTimers():
    # If game time is greater than the munchkinSpawnTime
    if game.time > game.munchkinSpawnTime:
        # Update the timer and spawn the munchkins.
        game.munchkinSpawnTime = game.munchkinSpawnTime + 6
        spawnMunchkins()
    # If game time is greater than potionSpawnTime
    if game.time > game.potionSpawnTime:
        player.say("The potion is here!")
        # Increase game.potionSpawnTime by 6:
        game.potionSpawnTime = game.potionSpawnTime + 6
        # Call the spawnPotion function:
        spawnPotion()
    # If game time is greater than throwerSpawnTime:
    if game.Time > game.throwerSpawnTime:
        # Increase game.throwerSpawnTime by 9:
        game.throwerSpawnTime = game.throwerSpawnTime + 9
        # Call the spawnThrowers function:
        spawnThrowers()
    # Update the UI timer until the next potion
    game.nextPotionIn = game.potionSpawnTime - game.time
    
while True:
    updateTimers()

    
    

@CHARLES_CRAWFORD found it! Spelling and caps count :wink:

Line 53 (from your original code, corrected for the +9 and the 2 unneeded lines):

    if game.Time > game.throwerSpawnTime:

My code combat must have a bug because none of this is working. Im going to repost on the bug forum.

Please don’t…it’s not a bug. Let me send you what I did and see how that goes first.

1 Like