I’m using a string with leading / following spaces. Coming from using other languages, I would always use “\s” to represent this in order to ensure the code is more readable (spaces before / after sentences often go unnoticed when re-reading code). However, when trying to write a string leading with “\s” on Roblox Studio just output “s” followed by the string as opposed to creating a blank space beforehand.
Example [Roblox Studio]:
print("\sHello world!")
Output:
Expected Output [Java]:
Output:
Is it possible to replicate on Roblox Studio without using the space key?
(I know it’s a niche problem but I code in abnormal ways)
I don’t want a new line, I want a space [" "], however if I type it as " " into the String it’s generally harder to notice (especially at the start / end of the string) than \s
I know this should be obvious but Lua and Java are 2 entirely different langauges and as such also have different rules and ways that strings are handled.
I would honestly just type this instead. print(" Hello world!")
I know it’s not the prettiest but this isn’t Java after all.
I recommend checking the documentation like some other suggested.
Fortunately Lua is fairly easy to pick up.
Oh, would \t work for this use case, then? (It’s the other special character mentioned on the “Strings” Roblox Creator Hub Guide that I referenced earlier.)
Interestingly, depending on the scale you have set for the Output in Roblox Studio, adding a singular \t could be the equivalent of 2 spaces or less (when it’s more zoomed in) or 4 spaces or greater (when it’s more zoomed out), so you may need to include a lot more or less depending on your preferred Output scaling.
For an extreme example, the last screenshot shows that using 3 \t in a row can visually appear the same as 4 spaces when using a very high scaling for the Output.
I’ll include screenshot examples after the codeblock for reference:
print("Example print for comparison")
print("\tHello world!") -- Print statement that uses \t
print(" 4 spaces added at the start, for comparison")
print("\t\t\tSo many spaces!") -- Print statement that uses \t 3 times
--[[ Output:
Example print for comparison
Hello world!
4 spaces added at the start, for comparison
So many spaces!
--]]