If itâs the % symbol thatâs causing the confusion Iâll try my best to elaborate on it a bit.
% is the modulus operator in Lua, and it returns the remainder after integer division between two numbers A and B
In simple terms, it just gets the remainder after diving A by B
In the code you can see that this is used in this line:
Status.Value = InitialString .. string.rep(".", i%3+1)
The line basically says: set Status.Value to InitialString (âYou will be playingâ) with i%3+1 dots after it. What does that mean?
Basically, letâs pretend were dividing i by 3. Remember that âiâ is the variable weâre using to loop over, so it takes values in between 0 and however many times you want it to loop (letâs say 10 times, so i takes values 0-9).
- At first, i = 0, so how many times does 3 go into 0? 0 times. Is there anything left over when dividing by 3? Nope, so i%3 = 0 in this case
- Letâs try i = 2 now, 3 goes into 2 a total of 0 times (still), but this time there is 2 left over when dividing by 3, so i%3 = 2.
- Now when i = 3, 3 now finally goes into 3 (i) once. But now there is nothing left over, so i%3 = 0.
- Likewise, when i = 4, i%3 = 1
You might be able to notice that performing i%3 only returns the values 0,1 or 2 depending on the remainder, restricting how high it can go. Thus, adding 1 to it will restrict it to the range 1-3.
When i = 0,1,2,3,4,5,6,7,8,9
i%3+1 = 1,2,3,1,2,3,1,2,3
Doing modulus with %3 is honestly pretty arbitrary, and I only chose it initially because it looks the nicest and itâs what youâll see in most games. You can change it to %4 if you want up to 4 dots, %5 if you want up to 5 dots etc.
I hope this helps but please ask if you have any other questions.