Cloudrip "Ice hunter" (python)

I need help with my code. It has an error for the sample/set up code, right here -

rightEdge = len(word) - len(substring)

My full code -

def isSubstring(word, substring):
    rightEdge = len(word) - len(substring)
    for i in range(rightEdge + 1):
        for j in range(len(substring)):
            shiftedIndex = i + j
            if word[shiftedIndex] != substring[j]:
                break
            if j == len(substring) - 1:
                return True
    
    return False

enemies = hero.findEnemies()
for e  in range(len(enemies)):
    enemy = enemies[e]
    isSubstring()
    if enemy.id == "bos":
        hero.attack("bos")

@Aya Idk who else. I really need help guys…

Ok, I figured out that the problem in

rightEdge = len(word) - len(substring)

Is because the line in

isSubstring()

Is empty, so I put

isSubstring( , "bos" )

For the “substring”, but what do I put for the “word”?

so here is the problem, as you said, isSubstring should take in 2 parameters, the word and the substring, so the word must be the enemy’s id, and the sub string should be “bos”, so here is the thing, you need to call the isSubstring function in the if statement, how it might look like:

if subString(enemy.id, "whatever the substring is") == True:
    #Do something

So I tried that, and I would hit each yak once, and then stop. So I figured I would need a while true look to fix it. And it still stops. The annoying part is that each yak is at about only 15 health. :expressionless:

def isSubstring(word, substring):
    rightEdge = len(word) - len(substring)
    for i in range(rightEdge + 1):
        for j in range(len(substring)):
            shiftedIndex = i + j
            if word[shiftedIndex] != substring[j]:
                break
            if j == len(substring) - 1:
                return True
    return False

enemies = hero.findEnemies()
for e  in range(len(enemies)):
    while True:
        enemy = enemies[e]
        if isSubstring(enemy.id, "bos"):
            if enemy.health >= 0:
                hero.attack(enemy)
        break

instead of checking its health, you can attack it twice, or if it needed more (based on your sword) you can make it 3 times

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.