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
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
Can someone give me a code for this?
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.
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.
@ChronistGilver My problem now is i cant stay clear of the orgs that are there.
ChronistGliver! Why don’t you hand us the code?
Scroll up a bit and you will get your answer:
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.
# 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