Say I need to find the multiples of 5, to check and see if a players level is a multiple of 5. How would I do this? I've done searches on many websites and I can't see that anybody's asked this really..
You can simply have an arithmetic check on the number you want to check if its a multiple or not.
The arithmetic operation is called "modulus", essentially what it does it checks the remainder of the division between 2 numbers and if it is 0 it means it is a multiple of that number ( the divisor ).
Here is an example with code:
1 | function returnIfMultiple(a, multiple) |
2 | if ((a % multiple) = = 0 ) then |
3 | print (a .. " is a multiple of " .. multiple .. " !" ); |
4 | else |
5 | print (a .. " is not a multiple of " .. multiple .. " !" ); |
6 | end ; |
7 | end ; |
As you can clearly see you give this function a number and the multiple you want to check with, in your example you want to check if a number is multiple of 5. You would simply do the mathematic operation 10%5
for example and that would return you 0 implying that 10 is indeed a multiple of 5. If you try to do the same operation with other number such as 11, the remainder that will be returned by the modulus operation will not be 0 therefore it is not a multiple of 5.
Make sure to ask any questions if you have any.
:)