0
So I’m having a problem with a loop for
in the code below:
for i=1,#collisionBlocks do
t=collisionBlocks[i]
print(#collisionBlocks)
print(i)
if player.y-1<t[4] and player.y-1>t[2] and ((player.x>=t[1] and player.x<=t[3]) or (player.x+50>=t[1] and player.x<=t[3])) then print'nao da para andar pra cima' return false end
return true
end
The table collisionBlocks
has 5 other tables inside, but the loop runs only once, being that it was to run 5 times since the table collisionBlocks
has 5 items inside it. So much so that if you perform the function that runs this loop, it will appear:
>5
>1
you should show up:
>5
>1
>5
>2
>5
>3
>5
>4
>5
>5
What are the
return
inside the loop? Does that belong to a function? If so, thereturn
will always finish the function, regardless of whether there are more iterations in the loop.– Woss
Ah, I know what’s causing it. The
return true
at the end of the loop was to be out of the loop right after it finished. Thank you very much!– arthurgps2
The show’s coming off
for
when I find anyreturn
. You have to think of a way to do this without using thereturn
.– Artur Brasil