-2

I'm building a program in Lua.

In my code, I have to translate count++ from Java to Lua. How would I go about this? I assume it's count = count + 1, but is there another way to go about this method?

Also, when you write (count % 20 == 0), is the right translation in Lua, (math.mod(count,20) == 0)?

I have tried both the above lines, but one of the two seem to be not working.

MasterAM
  • 16,283
  • 6
  • 45
  • 66
Jackrow102
  • 73
  • 1
  • 7
  • I have tried count = count + 1 in the (math.mod(count,20)==0) method. I tried debugging it and it seems that it's not working correctly. I am not sure which of the two is wrong. :/ – Jackrow102 Jul 05 '15 at 23:10
  • Ask one question per time. The two questions are not related. – Yu Hao Jul 06 '15 at 01:06
  • possible duplicate of [Lua replacement for the % operator](http://stackoverflow.com/questions/9695697/lua-replacement-for-the-operator) – Tom Blodget Jul 06 '15 at 16:17

1 Answers1

0

a % b == a - math.floor(a/b)*b

from: Lua replacement for the % operator

And count = count + 1 is fine

You can see this in action by pasting

count = 1 
count = count + 1
print(count)
print((count - math.floor(count/2)*2) == 0) --ie count % 2 == 0

into http://www.lua.org/cgi-bin/demo

Community
  • 1
  • 1
JDrost1818
  • 1,116
  • 1
  • 6
  • 23