String.format or string...the thing? Which is better?

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

It’s all preference bud! You can do whichever one comes off the top of your head. Personally I use …

1 Like

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.

1 Like

So we here is no performance impacts by using one or the other? I prefer performance and reliability.

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.

1 Like