Inserting Code Snippets - Guide for New Members

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

  1. Right click on the post body and click “Paste as plain text” or
  2. Press Control + Shift + V

Firefox

  1. 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?

  1. Highlight the pasted text and press Control + Shift + C or
  2. Highlight the pasted text and click the format button that can be found on the tool bar or
    image
  3. Put ``` above and below your code or
    image
  4. 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?

7 Likes

I think this is the wrong category. Isn’t this uhh… #learning-resources? :thinking:

4 Likes

According to About the Resources category, the main idea of the category is to…

  • Share key community resources
  • Check out Roblox Tutorial Series
  • Share useful development tutorials created by the community

…which all seem to be development related. I’m pretty sure developer forum tutorials fall in the inception forum category as the inception forum is just about the devforum in particular.

4 Likes

It doesn’t really belong… anywhere.

1 Like

I got confused when I read it first. :thinking:

Mindless skimming, I guess.

I was wondering why it would paste as quot and the symbols . Thank you this is very interesting information :slight_smile: and helps a lot of people too!

1 Like