ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 04 Feb 2012 06:47 PM |
In this experiment, we will create functions that are used to create lists, menus, frames, etc similar to my example below and see what all we come up with. Feel free to modify my simple getList function. It creates a list from a table of string values where '/' is used to denote another option.
IE {'hey','test','yes/no/cancel'} would create....
hey being 1 in length test being 1 in length yes|no|cancel each being .33 in length
function split(str, val) local found, members, pos; found = true; members = {}; repeat pos = str:find(val) or str:len()+1; table.insert(members, str:sub(1, pos-1)); if(pos == str:len()+1)then found=false; break; else str = str:sub(pos+1); end until found==false; return members; end
getList = function(list) local ySize = 1/#list; local xSize; local items = {}; for i = 0,#list-1 do local options = split(list[i+1],'/'); xSize = 1/#options; for x = 0,#options-1 do local option = options[x+1]; local option_btn = Instance.new('TextButton'); option_btn.Name = option; option_btn.Text = option; option_btn.Size = UDim2.new(xSize,0,ySize,0) option_btn.Position = UDim2.new(xSize*x, 0, ySize*i); table.insert(items, option_btn); end wait(); end return items; end |
|
|
| Report Abuse |
|
|
LocalChum
|
  |
| Joined: 04 Mar 2011 |
| Total Posts: 6906 |
|
|
| 04 Feb 2012 06:49 PM |
| I believe RbxGui can do something like this. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 05 Feb 2012 01:20 PM |
Why shoot yourself in the foot? Why use:
{'hey','test','yes/no/cancel'}
When you could just use
{'hey', 'test', {'yes', 'no', 'cancel'}}
Don't create work for yourself!
----
Also, your split function can be simplified greatly (although it probably runs more slowly this way):
function split(str, on) local results = {} (str..on):gsub("(.-)"..on, function(r) table.insert(results, r) end) return results end |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 05 Feb 2012 01:34 PM |
As a nice pattern for creating a list using GUI-objects, you can exploit the hierarchical nature of the Roblox GUI system:
Have all of the list items have their Position-Y-Offset be equal to their height, and then put each item as a child of the item which is above it. The Roblox layout engine will do the heavy work of ordering the list items one after another, and it still remains easy to remove a list item, without any special code to re-order the thing, all you have to do is remove the list item and then put it's child list item into it's parent. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 05 Feb 2012 01:58 PM |
| I've attempted to make a GUI thing [here](http://wiki.roblox.com/index.php/User:NXTBoy/Scripts/GUI), using stupid amounts of functions returning functions. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
| |
|
|
| 07 Feb 2012 09:05 PM |
@NXTBoy
Just wondering, why did you put these random brackets and parenthesis there..? |
|
|
| Report Abuse |
|
|
Intune
|
  |
| Joined: 02 Feb 2012 |
| Total Posts: 50 |
|
|
| 07 Feb 2012 10:28 PM |
@JulienDethurens
Same reason people like to put them around numbers. (I don't know the actual reason though) |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2012 04:55 AM |
"Same reason people like to put them around numbers. (I don't know the actual reason though)"
What..? |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 08 Feb 2012 01:24 PM |
| Which random brackets and parentheses? As far as I am aware, almost all of them are required. The only one I could remove would be to replace `item = item({})` with `item = item {}`, but that would be even more crytic! |
|
|
| Report Abuse |
|
|