Hack Forums
[Lua] Problem looping and switching between sprites - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Lua] Problem looping and switching between sprites (/showthread.php?tid=3984350)



Problem looping and switching between sprites - deadaimsave - Jan 8, 2014

Basically I have two images of a character to make it look like it's walking. I simply want him to walk across the screen.

My code uses the Corona SDK and since some of you might not be familiar with that, I'll just simplify it:
Code
for i = 0, 150, 2

   if sprite = 1 then
  move sprite over by current position + i
  sprite = 2
  pause for 500 miliseconds()
   end

   if sprite = 2 then
  move sprite over by current position + i
  sprite = 1
  pause for 500 miliseconds()
   end

end

When I run it, the character instantly moves to the ending position, only 1 frame change is noticeable, and all the "pauses" happen AFTER the loop is finished (when I debug, the loop starts, both the if statements are executed, and then it loops 74 more times without any if statements being executed. Then after looping is complete, it executes 2 pauses.)

I have no idea why this would happen and would appreciate any suggestions. Thanks!