Inserting code snippets can be infuriating when you can’t press the Tab key to indent your code properly, replace all the “"
” with proper quotation marks and don’t know how to insert a code snippet in the first place.
What is a Code Snippet?
The block of code that some posts may contain that look like this
local Text = "This is a code snippet."
local function PrintSnippet()
print(Text)
end
PrintSnippet()
How to insert code properly?
Before we delve further into inserting code from studio, let’s talk about Plain Text Format.
According to Computer Hope, Plain Text is any text, text file, or document that contains only text. Unlike a rich-text document, a plain text file cannot have bold text, fonts, larger font sizes, or any other special text formatting.
What does this have to do with code snippets?
When we copy a piece of code from studio, it is formatted in some kind of way for studio to understand it, which is why in some systems or applications, we have the option to either Paste or Paste as Plain Text.
When inserting code into a post, it has to be pasted in Plain Text Format to avoid these kind of snippet formats
game:GetService("Players")
local function PrintText()
print("Hello World!")
end
These kinds of snippet formats makes it difficult for other developers to help you with your code. It’s also a form of respect to make it effortless for other developers to help you by posting elegant looking snippets.
Chrome
- Right click on the post body and click “Paste as plain text” or
- Press Control + Shift + V
Firefox
- Press Control + Shift + V
Microsoft Edge
Unfortunately, I was unable to find any method to paste Plain Text straight away into the browser. If you know a method on how to do this or any extension please post them.
How to Format the pasted text as Lua Format?
- Highlight the pasted text and press Control + Shift + C or
- Highlight the pasted text and click the format button that can be found on the tool bar or
- Put ``` above and below your code or
- Put 4 spaces before a line of code
You obviously want your code to look like this
game:GetService("Players")
and not this
game:GetService(“Players”)
How to Indent code that I typed on my phone or directly on my post?
An indention is equivalent to 4 spaces. Only use this in code snippets! You may end up trying to indent other parts of a post that arent code which will turn into Lua Format.
4 Spaces = Indention and Lua Format
This is an indented text.
local Text = "This line of code is also indented"
References
Copy and Paste as plain Text in Chrome, Firefox browsers. (2014). Retrieved from
https://www.thewindowsclub.com/copy-and-paste-as-plain-text-chrome-firefox
What is Plain Text?. (2017). Retrieved from
What is Plain Text?