Log In  

--enemies
function make_enemies()
e1={}
e1.x=20
e1.y=10
e1.sprite=6
end

function move()
if e1.x >= 120 then move = false
if e1.x <= 10 then move = true
end
end
end
function move_enemies()
if move == true then e1.x = e1.x + 1
if move == false then e1.x = e1.x - 1
end
end
end
this code is not working it should work at the bigining it starts off true and when the enemy x is equile to 120 near the screen it turns to false making it go left

P#96408 2021-08-24 07:29 ( Edited 2021-08-26 09:40)

1

you put "nove" instead of "move".

P#96410 2021-08-24 07:47
1

thanks for that but it still does not work

P#96481 2021-08-26 09:41
1

In your code, you have one of your "end" keywords in the wrong place. If you do some indentation, you can see where the issue is:

function move_enemies()
   if move == true then e1.x = e1.x + 1
     if move == false then e1.x = e1.x - 1
     end
   end
end

So what you can see is that your check for false is inside your check for true, so it will never get run. What you want is this instead:

function move_enemies()
   if move == true then
     e1.x = e1.x + 1
   else
     e1.x = e1.x - 1
   end
end

That should do what you're expecting. Hope that helps!

P#96491 2021-08-26 11:50

i got it working thank you everyone for helping me out

P#96851 2021-09-04 03:30 ( Edited 2021-09-04 04:08)

[Please log in to post a comment]