User:Blocco/RbxGui: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Blocco
No edit summary
>Blocco
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
As with many of the current Libraries, <b>RbxGui</b> is a [[Lua Asset]] designed to assist with the making of [[GUI]] widgets.  This article will explain to you what <b>RbxGui</b> is, how to use it and how keep up with its ever-changing API.
{{EmphasisBox|color=red|dark=yes|<span style{{=}}"width:100%;display:inline-block;font-weight:bold;color:red;text-align:center;">This article is currently <i>in opere</i>, and can be changed at anytime.</span>}}
 
As with many of the current Libraries, <b>RbxGui</b> is a [[Lua Asset]] designed to assist with the making of [[GUI]] widgets.  This article will explain to you what <b>RbxGui</b> is, how to use it and how to keep up with its ever-changing API.
__TOC__
__TOC__


Line 46: Line 48:
== How do you figure out what's in this library? ==
== How do you figure out what's in this library? ==


To find all of the values in a library, you have to use a method found in every library, called GetApi.  This method allows you to see what exactly is in the library by returning a table of all of the function names in the library.  To figure out all of the values in RbxGui, simply run this code in your command bar in Studio:
To find all of the values in a library, you have to use a method found in every library, called ''GetApi''.  This method allows you to see what exactly is in the library by returning a table of all of the function names in the library.  To figure out all of the values in '''RbxGui''', simply run this code in your command bar in Studio:


<pre>table.foreach(LoadRobloxLibrary("RbxGui"):GetApi(), function(index, value) print(index, "=>", value) end)</pre>
<pre>table.foreach(LoadRobloxLibrary("RbxGui"):GetApi(), function(index, value) print(index, "=>", value) end)</pre>


This piece of code iterates through the table returned by GetApi and prints out the contents of the table.
This piece of code iterates through the table returned by ''GetApi'' and prints out the contents of the table.


Also, if it is an official library, there is often a Help function associated with it.  To use it, just call the Help function from the library loaded into your code.
Also, if it is an official library, there is often a ''Help'' function associated with it.  To use it, just call the ''Help'' function from the library loaded into your code.


== So, is that it? ==
== So, is that it? ==
Line 68: Line 70:
=== How do I know what's in the library? ===
=== How do I know what's in the library? ===


You have to iterate through the table returned by GetApi and print out the values of it.  You can also use the Help function in the library with the values of the table.
You have to iterate through the table returned by ''GetApi'' and print out the values of it.  You can also use the ''Help'' function in the library with the values of the table.


=== Concluding mumbo-jumbo ===
=== Concluding mumbo-jumbo ===


That's all there is to using the RbxGui library created by Roblox.  I hope you'll have as much joy using the library as I've had writing this article to teach you to use it.
That's all there is to using the RbxGui library created by Roblox.  I hope you'll have as much joy using the library as I've had writing this article to teach you to use it.

Latest revision as of 17:37, 12 July 2011

This article is currently in opere, and can be changed at anytime.

As with many of the current Libraries, RbxGui is a Lua Asset designed to assist with the making of GUI widgets. This article will explain to you what RbxGui is, how to use it and how to keep up with its ever-changing API.

What is RbxGui?

RbxGui is (as stated above) an official Roblox-created library specifically for aiding with the creation of GUI programs. Its use is not mandatory, but is recommended for those who would like to make good looking GUI features in lesser amounts of time.

How do I use RbxGui?

RbxGui is used by simply loading the library in your code and storing it in a variable. After that, one can easily use the various API functions and methods that the library has to offer. Below is some sample code that demonstrates the use of this library.

Note: This library uses fields instead of methods, so don't use a colon. Use a period instead.

Example
Below is example code designed for use in a LocalScript that goes in either the StarterGui or StarterPack that makes a list of objects and puts them in a drop down list.
function waitForChild(p, c) -- utility code; don't worry about this
	while not p:FindFirstChild(c) do
		p.ChildAdded:wait();
	end
	return p[c];
end

local library=LoadRobloxLibrary("RbxGui") -- load our "RbxGui" library

function onItemSelected(item) -- create our callback that gets called when an item gets selected
	-- arguments:  item (string)
	print("'" .. item .. "' was selected!");
end

local listOfItems={"This", "is", "a", "list", "of", "items."}; -- our list of items
local dropDownList, updateSelection=library.CreateDropDownMenu(listOfItems, onItemSelected); -- create the drop down list with our list and the callback
dropDownList.Size = UDim2.new(1, 0, 1, 0) -- this is to make the drop down list fit in our GUI correctly

local holderGui = Instance.new("ScreenGui"); -- make the screen gui that holds everything
local holderFrame = Instance.new("Frame"); -- make a frame to hold the drop down list
holderFrame.Size = UDim2.new(0, 200, 0, 26); -- make it the size you want
holderFrame.Position = UDim2.new(0.5, -100, 0.5, -20); -- position it the way you want (right now it's in the center)
holderFrame.BackgroundTransparency = 1; -- make it transparent for the drop down list
holderFrame.Parent = holderGui;

dropDownList.Parent = holderFrame; -- put the drop down list in the frame

if game.Players.LocalPlayer then -- make sure we have a player
	local playerGui = waitForChild(game.Players.LocalPlayer, "PlayerGui"); -- wait for playergui
	holderGui.Parent = playerGui; -- put the screen gui in the playergui
end


How do you figure out what's in this library?

To find all of the values in a library, you have to use a method found in every library, called GetApi. This method allows you to see what exactly is in the library by returning a table of all of the function names in the library. To figure out all of the values in RbxGui, simply run this code in your command bar in Studio:

table.foreach(LoadRobloxLibrary("RbxGui"):GetApi(), function(index, value) print(index, "=>", value) end)

This piece of code iterates through the table returned by GetApi and prints out the contents of the table.

Also, if it is an official library, there is often a Help function associated with it. To use it, just call the Help function from the library loaded into your code.

So, is that it?

That is all there is to it. Let's recap upon what we've learned today.

What is RbxGui?

RbxGui is an official Roblox-created library consisting of useful functions that are designed to help you make enticing GUIs.

How do I use it?

To use RbxGui, you must load it into your code and then call its members, which are designed to do things that would normally take more time to do.

How do I know what's in the library?

You have to iterate through the table returned by GetApi and print out the values of it. You can also use the Help function in the library with the values of the table.

Concluding mumbo-jumbo

That's all there is to using the RbxGui library created by Roblox. I hope you'll have as much joy using the library as I've had writing this article to teach you to use it.