(Lua) Trouble with Siege of Stonehold --- Bug?

Hey guys!
So I’ve been making my way through the levels within the forest area, and I have reached this level and hit a wall as an error prevents me from doing anything when I hit submit, however, I am unable to see what part of my code is causing the error in question. Basically, no error message will pop up and no error sign is shown in the code.
Here are images showing before and after running the code, and what it looks like when I submit it:




And here’s my code here:

-- Help your friends beat the minions that Thoktar sends against you.
-- You'll need great equipment and strategy to win.
-- Flags might help, but it's up to you–be creative!
-- There is a doctor behind the fence. Move to the X to get healed!
while true do
    local flag = hero:findFlag("green")
    local enemy = hero:findNearestEnemy()
    local distance = hero:distanceTo(enemy)
    if flag then
        hero:moveXY(flag.pos.x, flag.pos.y)
        hero:pickUpFlag(flag)
    end
    if enemy then
        if hero:isReady("cleave") then
            hero:cleave(enemy)
        else
            hero:attack(enemy)
        end
    else
        hero:moveXY(19, 69)
    end
end

Thanks in advance, hope i’m not that dumb lol :confused:

Hello! Welcome to the CodeCombat Discourse! :tada:

I’m not sure if that’s the problem that it causing an error, but

  1. You have a cleave command, however, you have equipped a sword which does not have cleave() method.
  2. In the flag section, you first move to the flag’s position, then pickup it. You don’t have to do that. Delete the line with moving and leave the pickup function only. It will be enough for your hero to move on the flag’s position.

I’ll change the topic category to Level Help, as your problem fits better there.

2 Likes

Thanks for responding! I reworked my code by removing the if statement for the cleave and the cleave itself and the flag’s moveXY command, however, it is still doing giving me that error and preventing me from moving whatsoever :frowning: . I tried fiddling around with it some more after that, by moving stuff around and adding/deleting things, but still nothing seems to change the error sign there.
New code here:

-- Help your friends beat the minions that Thoktar sends against you.
-- You'll need great equipment and strategy to win.
-- Flags might help, but it's up to you–be creative!
-- There is a doctor behind the fence. Move to the X to get healed!
while true do
    local flag = hero:findFlag()
    local enemy = hero:findNearestEnemy()
    local distance = hero:distanceTo(enemy)
    if flag then
        hero:pickUpFlag(flag)
    end
    if enemy then
        hero:attack(enemy)
    else
        hero:moveXY(19, 69)
    end
end