RbxLibrary: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
No edit summary
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">"
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== What is a library? ==
== What is a library? ==


In Roblox, the term '''library''' doesn't mean "an educational, academical place to gain informational knowledge."  Rather, libraries in Roblox are simply extensions of the <abbr title="Application Programming Interface">API</abbr>, which include developer-created Lua code which can be included in any script with ease.
In Roblox, the term '''library''' doesn't mean "an educational, academical place to gain informational knowledge."  Rather, <dfn>libraries</dfn> in Roblox are simply extensions of the <abbr title="Application Programming Interface">API</abbr>, which include developer-created Lua code which can be included in any script with ease.


== How do I use a library? ==
== How do I use a library? ==


To find out what methods are in the library, you can first check for documentation on the wiki, or search the forums. If they both come up with nothing, you'll probably need to do lots of experimenting. Here's some base code to use:
To find out what methods are in the library, you can first check for documentation on the wiki, or search the forums. A preferrable way, but slightly more complicated, is to use the library's built-in documentation.
<code lua>
 
First, we need to load the library, which can be done with the [[LoadLibrary (Function)|LoadLibrary]] function:
<syntaxhighlight lang="lua">
assert(LoadLibrary('RbxGui'))
assert(LoadLibrary('RbxGui'))
</code>
</syntaxhighlight>
That loads the contents of [[RbxGui (Library)|RbxGui]], a library. However, we need to store it in a [[variable]].
That loads the contents of [[RbxGui (Library)|RbxGui]], a library. However, we need to store it in a [[variable]], to use it.
<code lua>
<syntaxhighlight lang="lua">
local RbxGui = assert(LoadLibrary('RbxGui'))
local RbxGui = assert(LoadLibrary('RbxGui'))
</code>
</syntaxhighlight>
Now, to see the contents, we can use a simple loop, with the handy GetApi method:
Now, to see the contents, we can use a simple loop, with the handy GetApi method:
<code lua>
{{code|=
for _, val in pairs(RbxGui:GetApi()) do
for _, val in pairs(RbxGui:GetApi()) do
    print(val)
print(val)
end
end
</code>
}}
That will print everything in the table out for us, so we know at least what there is in there.
That will print everything in the table out for us, so we know at least what there is in there.


Then, we can find how to use the functions that are in the library using the [[Help (Function)|Help]] function. All the libraries have an [[Help (Function)|Help]] function that lets us know how to use the functions it contains. Let's try with the [[CreateSlider (Function)|CreateSlider]] function:
Then, we can find how to use the functions that are in the library using the [[Help (Function)|Help]] function. All the libraries have an [[Help (Function)|Help]] function that lets us know how to use the functions it contains. Let's try with the [[CreateSlider (Function)|CreateSlider]] function:


<code lua>
<syntaxhighlight lang="lua">
local RbxGui = assert(LoadLibrary('RbxGui'))
local RbxGui = assert(LoadLibrary('RbxGui'))
print(RbxGui.Help("CreateSlider"))
print(RbxGui.Help("CreateSlider"))
</code>
</syntaxhighlight>


This will print some informations about how to use the function in the output.
This will print some informations about how to use the function in the output.
Line 36: Line 38:
*[[RbxStatus (Library)|RbxStatus]]
*[[RbxStatus (Library)|RbxStatus]]
*[[RbxGear (Library)|RbxGear]]
*[[RbxGear (Library)|RbxGear]]
*[[RbxStamper (Library)|RbxStamper]]

Latest revision as of 06:03, 27 April 2023

What is a library?

In Roblox, the term library doesn't mean "an educational, academical place to gain informational knowledge." Rather, libraries in Roblox are simply extensions of the API, which include developer-created Lua code which can be included in any script with ease.

How do I use a library?

To find out what methods are in the library, you can first check for documentation on the wiki, or search the forums. A preferrable way, but slightly more complicated, is to use the library's built-in documentation.

First, we need to load the library, which can be done with the LoadLibrary function:

assert(LoadLibrary('RbxGui'))

That loads the contents of RbxGui, a library. However, we need to store it in a variable, to use it.

local RbxGui = assert(LoadLibrary('RbxGui'))

Now, to see the contents, we can use a simple loop, with the handy GetApi method:

for _, val in pairs(RbxGui:GetApi()) do
	print(val)
end

That will print everything in the table out for us, so we know at least what there is in there.

Then, we can find how to use the functions that are in the library using the Help function. All the libraries have an Help function that lets us know how to use the functions it contains. Let's try with the CreateSlider function:

local RbxGui = assert(LoadLibrary('RbxGui'))
print(RbxGui.Help("CreateSlider"))

This will print some informations about how to use the function in the output.

Existing Libraries

Here is a list of the currently existing libraries: