Continuous Alchemy Python Solved


#1

The problem is my hero moves to late after the water is thrown and the ogre gets it and kills me there are other times where poison is thrown and the ogre drinks it but then water is thrown and poison a few seconds later and my hero drinks the water with the poison and then dies

# Race munchkins to the water distilled by Omarn Brewstone!
# The continue statement is powerful for managing complicated logic.
# When the program uses the continue statement, the rest of the loop is skipped.
# However, unlike with "break", the loop repeats instead of stopping.
# Use "continue" to verify the conditions of the ambush.
myX = self.pos.x
myY = self.pos.y
# If there is no enemy, continue out of the loop.
loop:
    enemy = self.findNearest(self.findEnemies())
    item = self.findNearest(self.findItems())

    if not enemy:
        continue
    self.say("I see an enemy!")
    # If there is an enemy, but no item, ask for a potion and continue out of the loop.
    if not item:
        self.say("Give me a drink!")
        continue
    
    # Use an if-statement to check the item's type. If the type is "poison", continue out of the loop.
    if item.type is "poison":
        continue
      
    # If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!

    self.moveXY(item.pos.x, item.pos.y)
    self.moveXY(myX, myY)

#2

In every loop iteration your hero is saying something when he sees an enemy. The say function will last around one second, time you can better spend by doing something else, like grabbing the healthy water.


Continuous Alchemy (Python)
#3

Could you show me what it should look like


#4

Your hero must shut the [redacted, no swearing is allowed] up when he sees an enemy. Thats all.

You know tv series where the main villian is talking and talking while the good guys do important stuff, like finishing him off? Yeah thats your hero currently. While he says “I see an enemy!” the mentioned enemy will sneak past your guard and grab the water.

Just keep it simple:
Call for a drink if you must.
If there is a healthy drink which is no poison: Grab the drink and walk back to your start position. Dont be talky.


#5

Just remove the self.say which comments on the presence of an enemy.


#6

i did but then my hero wouldnt move


#7
# Race munchkins to the water distilled by Omarn Brewstone!
# The continue statement is powerful for managing complicated logic.
# When the program uses the continue statement, the rest of the loop is skipped.
# However, unlike with "break", the loop repeats instead of stopping.
# Use "continue" to verify the conditions of the ambush.
myX = self.pos.x
myY = self.pos.y
# If there is no enemy, continue out of the loop.
loop:
    enemy = self.findNearest(self.findEnemies())
    item = self.findNearest(self.findItems())
    
    if not enemy:
        continue
    
    #self.say("hey, there's an enemy!")
    # If there is an enemy, but no item, ask for a potion and continue out of the loop.
    self.say("Give me a potion!")
    continue
    if not item:
        continue
    
    # Use an if-statement to check the item's type. If the type is "poison", continue out of the loop.
    if item.type is "water":
        
        self.moveXY(item.pos.x, item.pos.y)
        self.moveXY(myX, myY)
        self.say("Ahhhhhhh, water")
    # If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!
    else:
        continue

#8

my hero wont move also can you show me what my code should look like


#9

Could you post the code correctly formatted? I am not a python coder but I believe the intendation is important and the currently posted code reveals problems with that.


#10

i dont see anything wrong with the indentation


#11

And I dont see anything correct with the current state of the code. Please post the formatted code or paste the code to pastebin or something alike.


#12

Thanks to Nick The Dear Leader of the Code for helping me with the code its now solved.
[redacted, no posting correct code]


#13

Please remove the prompt to say something when seeing an enemy. It was very frustrating to my 10 year old novice programmer, and took me looking at it to realize the timing disaster. Simply commenting out his self.say(“Oooo, there’s one!”) completely fixed it.

Now, I have the harder job of explaining why commenting it out fixed the timing issues without losing him in the weeds.


#14

@jasont See @Marrrk’s comment above, it is explained very well there.

I agree that the initial code should not contain a call to the say() method. The initial code is never supposed to lead to a non-obvious lose condition.


#15

Why do none of your codes work? My amara arrowhead doesn’t even move, in the code I modified it and amara was lazy and died:dizzy_face:


#16

:dizzy_face: is an emoji


#17

made by CODING!!!


#18

That’s because we don’t post solutions in the forums. Please see the FAQ and post the code that you need help with.


#19

:stuck_out_tongue_winking_eye:


#20

Please do not revive dead threads unless you have a related issue. :stuck_out_tongue_winking_eye: is not relevant to the discussion.