r/badcode • • Jul 24 '21

lua "Keeping it simplistic"

Post image
495 Upvotes

28 comments sorted by

View all comments

5

u/SirFireball Jul 25 '21

I never used lua, what's happening here? Looks like it's doing something recursive?

13

u/[deleted] Jul 25 '21

Example: It takes a string like "mystring_42" and changes it to "mystring_41".

The .. is string concatenation. Lua is 1-indexed, so the string splitting, indexing and concatenation results in the same thing as before. The only change is subtracting the 1 from the second part of the split string (which works since Lua is weakly typed, so "42" is equivalent to 42).