Thirsty Panther 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 comment Share on other sites More sharing options...
catch22 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 Coding for Christ. Link to comment Share on other sites More sharing options...
gamecreator 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 comment Share on other sites More sharing options...
Thirsty Panther 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. 1 Quote Link to comment Share on other sites More sharing options...
Slastraf 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 comment Share on other sites More sharing options...
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.