I’m trying to make my code future-proof so I don’t have to remember how a certain function are used. I would like to know if I can make “Example Code” like in the image and how to do it.
You can’t; the code samples are built-in by roblox. The most you can do to achieve a similar effect would be making a code sample in a multi-line comment near the function
The Code Examples are generally provided by Official Roblox Documentation, but to more Specific in this context, the Instance:GetDescendants() Documentation which has the said Code Sample from the Image, They are basically just Built-In Examples like with function Comments like what the person above said.
--[[ Multi-Line Comment
Hi, This is a Multi-Line Comment,
If it wasn't obvious.
print(11) -- no action, commented out.
--]]
---[[ an extra hyphen disables the Comment:
print(11) --> 11
--]]
--[===[ Long Comment (I still have a hard time telling the difference between them)
I swear I literally have no idea what the difference, they appear the same thing.
Are they the same thing or am I an idiot? I have no idea?????????????????
--]===]
Anyway, Basic things.
You cannot necessarily add this. However, you can make your code nearly future proof by using new methods that won’t change, like most of the members of Instance
. Also, you can organize these into module scripts, so you don’t have a hard time updating them.
Nah:
-- This a single-line statement.
--[[
Double quotes denote that this is a long string.
Which means it can span as many lines as you want, lol.
Hi.
More lines.
]]
Replying to the OP, I think the best way is just to actually remember how they’re used. Methods’ names give you a clear description of what it does, in this case, :GetDescendants()
means “Get all the descendants of the Instance that is calling this method on”.
If you really need an example code because we sometimes forget about stuff, you can comment out what methods do:
--[[
:GetDescendants(): Returns an array containing all of the descendants of the instance.
Code example:
local descendants = workspace:GetDescendants()
-- descendants is now an array, containing all descendants in workspace
-- ...
]]
local whatever = workspace:GetDescendants()
-- ...
Or, you can always go to the Documentation website to look for a specific class or method to see what they do, instead of typing it in the editor.
you can’t and the samples are built by roblox, and all of these can even be found on the documentation and I think you should create a post on #resources:community-resources if it’s free or open source, if not, then post it on #help-and-feedback:creations-feedback also I’m not sure if you want to make code future-proof
the closest you can get is type checking
you can set a type as a string
type Example='this will convert this to that'
function convert():Example
end
when ever you type in convert it will display the string. although this is the closest and I do not recommend as it will not see the output of convert as what it is supposed to be but as a string that says ‘this will convert this to that’
It’s actually possible using the script editor API. You can add a callback to the autocomplete to add descriptions and examples to the list of autocomplete fields.
Interesting, I wasn’t actually aware of this (I haven’t seen it used much though)!
But I’m not sure how useful it’ll be to the OP since they would need to create a plugin for it
Thanks alot for this information. This is probably gonna help alot with modulescripts. and I havent really used typechecking but putting it in a module script really speeded up my production.
Can you give an example, please?
I suggest properly commenting in your code and using type checking. That + staying consistent with naming conventions and styling are good ways to ‘future proof’ your code.
I don’t personally have too much experience with it but basically each time a script is updated, autocomplete callbacks (functions) are invoked, these functions can mutate the table (which is passed to the callback) that contains information about the autocomplete. That is to add or remove from the table, and this new entry will pop up in/be removed from the autocomplete box. I only really briefly played around with it but as I don’t make plugins, I didn’t make anything super in-depth. But it shouldn’t be too hard to write a simple command line script that lets you add a random test entry by registering a callback function.
It’s similar to TextChatService’s message options in that you can return an updated version of an old object to change the message’s behaviour and how it looks visually.
I had to read through it for an hour to understand how to use it, It also doesnt really detect types in variable which is a downside.
Though you cannot do it like Roblox, you can comment in scripts defining what they do. But if you don’t want to go through the script to see what it does, you could use this plugin: Documentation Reader - A Plugin for Scripters!
[=====================[
In Lua, you can place as many equal signs as you want between the square brackets and it will still work.
Additionally, you can have other nested quotes inside!
[[
More stuff here.
]]
]=====================]