Problem with self healing minesweeper


#1

my scipt:

loop:
    item = self.findNearestItem()
    currentHealth = self.health
    healthThreshold = self.maxHealth / 2
    if currentHealth < healthThreshold:
        self.moveXY(self.pos.x - 10, self.pos.y)
        self.say("heal me!")
    elif item:
        itemPos = item.pos
        itemx = itemPos.x
        itemy = itemPos.y
        self.moveXY(itemx, itemy)

at the end he keep repeating this part until dies:

elif item:
        itemPos = item.pos
        itemx = itemPos.x
        itemy = itemPos.y
        self.moveXY(itemx, itemy)

then suddenly use this part:

 self.moveXY(self.pos.x - 10, self.pos.y)
 self.say("heal me!")

but it is already too late


#2

Hi Giedrius_Haze

Please use three backticks (```) in the future to present your code in a nice and organized way. You can read the FAQ (which you should have anyway) to see how exactly to do this.


To your problem.
At the first look I can’t see any problem with it. Please use self.say(self.health) at the start of the loop. Maybe it is a bug with the variable not properly decreasing (I think there were some problems once, but I thought they were resolved…).

I solved the level once with pretty much the same code, but I die as well.


EDIT: Ah, I found the problem (kind of). I followed my own advice and added some say-commands. By the time were you are flung in the air, you received no damage. Your program still uses the old value, which is above the threshold. It selects the next mine and moves to it. During this move, self.health is updated. But that is too late. You already move, and nothing will stop you (well, except the next mine of course).
I don’t really have a solution for this though right now. You could try with boots that use move rather than moveXY, or flags (though this is not the intended way). I contact @nick about it.


#3

This issue is now tracked on GitHub. If possible, please provide any additional information there to solve this problem as fast as possible.


#4

Should be fixed now; give it another go!


#5

script went well from very first run. thnx