Hello! When I see popular kits, such as ZonePlus, on their website, they use code examples with string.format(). However, I use string.. number for example.
Which should I use?
Option 1:
"This player's name is ".. Player.Name
Option 2:
string.format("This player's name is %s", Player.Name)
Which is more reliable and should be used? Thanks! WE
Personally, I believe that option 2 is a lot more readable. For small changes, like you’ve shown in option1, it isn’t too bad, but lets pretend you’re making a calculator. All of a sudden, you’ve got to print something like this:
print(a.." x "..b.." = "..a*b)
That is really hard to read, and going back on your code it’d make it a bit more confusing. However, using string.format, that mess becomes something more readable, as follows:
print(string.format("%f x %f = %f", a, b, a*b))
However, as @Thanks4DaLimbs rightfully said, it really is just preference.
What @Thanks4DaLimbs said, better string.format when they are texts that are repeated many times or for translations and there seems to be no change in performance.