Script Templates and conditions for them

As a Roblox developer, it is currently time consuming to write out portions of a script that are near identical to others, whether this be for documentation, or global functionality. This is why I believe we should be able to have script templates that are automatically pasted into any script you create, instead of the default “Hello, World” program. This could improve development time and quality of life for most developers, and may even be able to become more advanced if something like conditions were introduced to templates, allowing multiple templates for different occasions (e.g location of the script, type of script, name of script).

If Roblox is able to address this issue, it would improve my development experience because we would no longer have to write out the same comments and services in all of my scripts. Many other game engines already have this feature - for example, unity - and with my experience lowers time to complete a program a significant amount.

2 Likes

Hi @SuchASaltyLemon! Thank you for the feedback? Which types of code templates would be most useful? Any examples would be really helpful. We’re also looking into code snippets where you can reuse the same code throughout your scripts

1 Like

While I am not the OP i have my own feedback.

As you can see in repl.it when there is no text there will be placeholder text. You can click on the examples text and it will give you some examples.


And perhaps something similar to how visual studio does this.

When you press tab twice when the intellisense suggests for, it will autocomplete the entire body. Then the identifier is highlighted, from there a name would be chosen. Then pressing tab again would highlight select the goal, then pressing tab again would go to the step in a for loop.

1 Like

Snippets sounds amazing and are a huge help when using IDEs. In terms of templates, I was thinking you could maybe have a page where you could make a custom template, and all new scripts would automatically paste these in. This could also become more advanced where it could use the context of the script to determine the template (e.g if your script is local, you might automatically want to make a variable for the player as you will need this for most local scripts). As you and @sjr04 both mentioned, snippets would be amazing. This could help dramatically speed up all work in studio, and I really hope this is something that could come in the future.

As you asked for examples of templates, I will give a few that I would regularly use:

Local script

-- Services
local Players = game:GetService("Players");

-- Variables
local localPlayer = Players.LocalPlayer;

For most module scripts, I will use something similar to this:

-- Variables
local x = {};
local mt = {};
    mt.__index = mt;

-- Functions
function x.new()
    local self = setmetatable(x, mt);

    return self;

end

return x;

It could also be interesting if it would prompt you to give a name to select variables in your templates (in my example, x), so you could more easily customise your code, as Ctrl+F can sometimes find variables you don’t want to change. Obviously, this is getting into territory where the situation may be too specific, but it is still something that could help.

1 Like