Help with stillness in motion level? LUPA programming language


#1

Im stuck on this level and i cant get passed it

I am using LUPA as my codes

heres my code…

loop
    local enemy = self:findNearestEnemy()
    if enemy then
    self:attack(enemy)
    self:attack(enemy)
    self:cleave(enemy)
    
end 

:rage:


#2

Can someone give me a code for this?


#3

Hello, LearningCodes, and welcome. Please read the FAQ and learn how to format your code properly prior to your next post. I’ve done it for you this time, but do so yourself in the future.


Here on CodeCombat, we don’t give out code as a regular policy. This game is intended to teach you coding. You don’t learn from just getting the answers.

Just telling us things like “I need help!” or “This code doesn’t work!” are not helpful to us. It is better to go into detail about your problem. However, here is what I can see:

You appear to only have one end in your code. You need an end for a loop and one for the if-statement. That appears to be your problem.


#4

@ChronistGilver My problem now is i cant stay clear of the orgs that are there.:unamused:


#5

ChronistGliver! Why don’t you hand us the code?


#6

Scroll up a bit and you will get your answer:


#9

I type in this code

loop:
enemy = self.findNearest(self.findEnemies())
# If there is an enemy, then…
if enemy:
# Create a distance variable with distanceTo.
distance = self.distanceTo(enemy)

    # If the distance is less than 5 meters, then attack.
    if distance > 5:
        self.attack(enemy)
        
    
    # Else (the enemy is far away), then shield.
    self.shield()
    
    
    pass
# Else (there is no enemy)...
else:
    # ... then move back to the X.
    self.moveXY(40, 34)

But the headhunters still are able to attack me. I did what they said will you please point ot the problems with this code.


#10
# If the distance is less than 5 meters, then attack.
    if distance > 5:

You mixed the comparison signs. This is a less than b:

a < b

#11

What is wrong with my code

:disappointed: