Thirsty Panther 392 Posted May 9 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 Share this post Link to post

catch22 23 Posted May 9 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 Share this post Link to post

gamecreator 746 Posted May 10 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 Share this post Link to post

Thirsty Panther 392 Posted May 11 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 Share this post Link to post

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