Thirsty Panther 446 Posted May 9, 2019 Share Posted May 9, 2019 How do I tell if a variable is odd or even using Lua? % is used in other languages is it the same with Leadwerks? Quote Link to post

catch22 25 Posted May 9, 2019 Share Posted May 9, 2019 Seems Lua doesn't have a modulo operator prior to 5.1 (not sure what LE is at the moment). a % b == a - math.floor(a/b)*b You can also try math.mod or fmod. from: https://stackoverflow.com/questions/9695697/lua-replacement-for-the-operator Quote Link to post

gamecreator 875 Posted May 10, 2019 Share Posted May 10, 2019 I don't know if Lua does integer math but you can divide the number by 2 then multiply it back by 2 and see if it becomes the same number. In C it looks like this: if ((n/2)*2 == n) printf("Even\n"); else printf("Odd\n"); For example, 7 divided by 2 would become 3 (because 3.5 becomes 3 when it's an integer) and would then double to 6. Since 7 doesn't equal 6, you know it was an odd number. (Credit: https://www.programmingsimplified.com/c/source-code/c-program-check-odd-even) Quote Link to post

Thirsty Panther 446 Posted May 11, 2019 Author Share Posted May 11, 2019 Thanks Catch and GC for the help. Turns out that Leadwerks does recognize the % as modulo. So if X%2 equals 0 then its an even number and if X%2 does not equal 0 its an odd number. Changing the 2 to other numbers will be true if the x is a multiple of that number. Now back to making a hex map. Quote Link to post

Slastraf 106 Posted May 13, 2019 Share Posted May 13, 2019 or go into 3d and make fractals with modulo.. altoguh u would use cpp for that Quote Link to post

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Note:Your post will require moderator approval before it will be visible.