[Solved]The Final Kithmaze With Lua

So I trying to but i can seem to figure out what im doing wrong it wont seem to attack the enemy i can move around just fine but i also cant figure out to automate move to gems with the find nearest items function

the code I’m using currently is

while true do
       local enemy1 = hero:findNearestEnemy()
       self:moveRight()
       self:moveUp()
       self:attack(enemy1)
       self:attack(enemy1)
       self:moveRight()
end
1 Like

Even i don’t know lua, but you should need loop i guess

do you mean the while true do part because i do have that it just didn’t show up when i put backticks

1 Like

So, screen shot? pls?

Screenshot (8)

1 Like

I think you don’t need end

Does it show where the errors?

it move right then up but does not attack the enemy

1 Like

even though the enemy is in the hero’s sight by then

1 Like

try making another move to the right before attacking the enemy

2 Likes

it ends the same way

1 Like

I don’t know then, i have to sleep now, bye

1 Like

okay thanks for the help anyway

1 Like

You can @Jason_king_lin , if you want more help

1 Like

Yeah, i found the problem

2 Likes

Where???
Where is the problem

1 Like

The thing is, you (@TheCelestial ) have to define enemy right before attacking, and the line i told you to add, you should remove it, and then make sure you go down twice after moving right after attacking the enemy

2 Likes

So put the “findEnemy” function “on” the attack method, right?
@Aya

1 Like

i dont understand, what s/he should do is move right, then up, then define enemy local enemy = hero:findNearestEnemy() and then attack the enemy twice, then move to the right, then go down twice and then move up

1 Like

Maybe he/she is a beginer?