Template:Callback/doc: Difference between revisions
>JulienDethurens *facepalm* |
Adding categories |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Documentation subpage}} | |||
This template is used to document callbacks. It should only be used to document callbacks that are part of the ROBLOX API and should <strong>never</strong> be used to document functions, methods, or anything that isn't a callback. | This template is used to document callbacks. It should only be used to document callbacks that are part of the ROBLOX API and should <strong>never</strong> be used to document functions, methods, or anything that isn't a callback. | ||
== Usage == | == Usage == | ||
<pre> | |||
<pre><nowiki> | <only<nowiki></nowiki>include>{{Callback | ||
< | |||
|name='''name''' | |name='''name''' | ||
|description='''description''' | |description='''description''' | ||
[| | [|parameters='''parameters'''] | ||
[|returns='''returns'''] | |||
[|object='''object'''] | [|object='''object'''] | ||
[|objects='''objects'''] | [|objects='''objects'''] | ||
}}</ | }}</only<nowiki></nowiki>include> | ||
</nowiki></pre> | </pre> | ||
Note: text between brackets ([ and ]) is optional, text in bold represents a certain value (something you must replace) and the rest represents things that must be present as-is. | Note: text between brackets ([ and ]) is optional, text in bold represents a certain value (something you must replace) and the rest represents things that must be present as-is. | ||
== Options == | |||
== | |||
;name | ;name | ||
:The name of the callback. | : The name of the callback. | ||
; | ;parameters | ||
:The | : The values passed to the callback. See the section on [[#parameters|parameters]] for more info on parameters. | ||
;returns | |||
: The types of the values that the callback function should return. Do not give them a name, only give their type. If they can be confusing, explain them in the description. If this argument is not specified, it will be indicated that the callback does not return anything. | |||
;description | ;description | ||
:A description of the callback. | : A description of the callback. | ||
;object | ;object | ||
:The name of the object the callback belongs to, if there is only one. Otherwise, use the objects | : The name of the object the callback belongs to, if there is only one. Otherwise, use the objects option. | ||
;objects | ;objects | ||
:Links to the objects the callback belongs to, if there are more than one. Otherwise, use the object | : Links to the objects the callback belongs to, if there are more than one. Otherwise, use the object option. | ||
== Parameters == | |||
== | Parameters are formatted similarly to [[Template:Method#arguments|arguments]] in the [[:Template:Method|Method Template]]. They should be separated by commas. Their type should <strong>always</strong> be written before their name and should <strong>always</strong> be identical to the one written in the object browser. The type should either be in raw text, either be a link to the page of the type or either be displayed with the {{Tl|Type}} template. The name should always either be contained in a {{Tag|var}} tag, which is preferable, either be italicized with wiki markup. | ||
Default values for arguments should be indicated outside of the {{Tag|var}} or outside of the italicization and be indicated the same way as they are in the object browser. | |||
== Callbacks == | == Callbacks == | ||
{{Main|Callback (Tutorial)}} | |||
Callbacks are not exactly the same thing as methods, even though they share a similar icon. If you look closely at their icon and compare it to the icon of methods, you will notice some differences. Callbacks are used in the following way: | Callbacks are not exactly the same thing as methods, even though they share a similar icon. If you look closely at their icon and compare it to the icon of methods, you will notice some differences. Callbacks are used in the following way: | ||
{{code|= | {{code|= | ||
Object.Callback = function | Object.Callback = function (param1) | ||
return val1 | |||
end | |||
}} | }} | ||
In the code above, ''Object'' is an object, ''Callback'' is the name of a callback belonging to the object, and ''function'' is a function that will be set as the callback. ''param1'' is the parameter passed to the function when it is called, and ''val1'' is the value the function should return. | |||
In the code above, | |||
== Notes == | == Notes == | ||
* If you need to put things after the callback, make sure to use the {{Tl|Clear floats}} template between the method and the rest of the page. | |||
*If you need to put things after the callback, make sure to use the {{ | * All callbacks should be categorized under the [[:Category:Callbacks|Callbacks]] category. | ||
*All callbacks should be categorized under the [[:Category:Callbacks|Callbacks]] category. | <includeonly> | ||
[[Category:Templates]] | |||
</includeonly> |
Latest revision as of 23:12, 29 May 2023
This is a documentation subpage for Template:Callback.
It contains usage information, categories and other content that is not part of the original template page.
This template is used to document callbacks. It should only be used to document callbacks that are part of the ROBLOX API and should never be used to document functions, methods, or anything that isn't a callback.
Usage
<onlyinclude>{{Callback |name='''name''' |description='''description''' [|parameters='''parameters'''] [|returns='''returns'''] [|object='''object'''] [|objects='''objects'''] }}</onlyinclude>
Note: text between brackets ([ and ]) is optional, text in bold represents a certain value (something you must replace) and the rest represents things that must be present as-is.
Options
- name
- The name of the callback.
- parameters
- The values passed to the callback. See the section on parameters for more info on parameters.
- returns
- The types of the values that the callback function should return. Do not give them a name, only give their type. If they can be confusing, explain them in the description. If this argument is not specified, it will be indicated that the callback does not return anything.
- description
- A description of the callback.
- object
- The name of the object the callback belongs to, if there is only one. Otherwise, use the objects option.
- objects
- Links to the objects the callback belongs to, if there are more than one. Otherwise, use the object option.
Parameters
Parameters are formatted similarly to arguments in the Method Template. They should be separated by commas. Their type should always be written before their name and should always be identical to the one written in the object browser. The type should either be in raw text, either be a link to the page of the type or either be displayed with the {{Type}} template. The name should always either be contained in a <var> tag, which is preferable, either be italicized with wiki markup.
Default values for arguments should be indicated outside of the <var> or outside of the italicization and be indicated the same way as they are in the object browser.
Callbacks
Callbacks are not exactly the same thing as methods, even though they share a similar icon. If you look closely at their icon and compare it to the icon of methods, you will notice some differences. Callbacks are used in the following way:
Object.Callback = function (param1)
return val1
end
In the code above, Object is an object, Callback is the name of a callback belonging to the object, and function is a function that will be set as the callback. param1 is the parameter passed to the function when it is called, and val1 is the value the function should return.
Notes
- If you need to put things after the callback, make sure to use the {{Clear floats}} template between the method and the rest of the page.
- All callbacks should be categorized under the Callbacks category.