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

Sarven Sum noob

hi!
actually i have a very weak understanding about what’s going on with my code =) especially i’m always messing up with spacing and index incrementing. can someone tell me the way to improve this code. this is everything that i know for this moment, but i’ve spied a part of solution on a github.

loop:
    whiteX = {'x':27, 'y':42}
    items = self.findItems()
    traps = self.findByType("fire-trap")
    trapsIndex = 0
    min = 9999
    max = 0
    enemies = self.findEnemies()
    enemyIndex =0
    while trapsIndex < len(traps):
            trap = traps[trapsIndex]
            if trap.value < min:
               min = trap.value
            if trap.value > max:
               max = trap.value 
    trapIndex += 1
    value = min + max   
    self.move(whiteX)
    self.say(value)
             
    if enemyIndex < len(enemies):
             enemy = enemies[enemyIndex]
             enemyIndex += 1
             if enemy:
                self.attack(enemy)

shouldn’t this:

if enemyIndex < len(enemies):

be this?

for enemyIndex < len(enemies):

oh, there should be while, no? i have not yet learned for

You use “for” in the code above… and it is formatted incorrectly. It looks like that should be a “while”. I am not sure what you are doing with trap values either.

Your spacing under the current for loop and the if enemyIndex look wrong.

I’m edited my code, but still need help

@Alex_Captain You need to increment your index within the while loop:

    while trapsIndex < len(traps):
        # blabla
        trapIndex += 1         # note the indentation!

Furthermore, this part doesn’t need to be in a loop - you have to do it only once. The loop should start after that. Structure your code somehow like this:

# find the min and max values
# go to white X
# say the result

loop:
    # if there is an enemy
        # fight it
    # otherwise
        # move towards the exit

One last word of advice: the easiest way to fight enemies is to find the nearest one and attack it (if there is one).

Happy coding!

hello there im having no luck in giving kitty the answer ,i need some assistance please

Hi, if you need help please post your code and explain your problem.
Thanks,
:lion: :lion: :lion:

First of all I can see that the code inside the while(true) loop isn’t indented (put 4 spaces forward).
And there’s more code at the top of the page which I can’t see, which might be causing the error.
Please could you post you code straight onto the Discourse, not take a screenshot.
Also make sure you format it, if you don’t know how to do that read this topic: link
Thanks,
:lion: :lion: :lion:

I’ll add two details.

  1. With this being javascript, indentation isn’t required like Python, but very helpful.
  2. The big piece is you can’t hard code the answer for the traps, but need to write code, functions being a suggestion, to find the answer since every time you submit, the trap values will be different.

Once you get past the traps, you should be ok if you have good enough armor and weapon.

those are the details im already aware of,and i cannot hard code this problem ,ill just come back to it later