hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 09:36 AM |
Hi everybody, I have a workspace with 3 models. Each model has a value and a id. Model 1: Value:3 ID:23920 Model 2: Value:1 ID:29104 Model 3: Value:2 ID:92030
Is there a PlayerGUI script which loops through the models and organizes them based on their value? And after that showing their ID in that order. Is there also a GUIscript which still works after I add more models?
Thanks for helping! |
|
|
| Report Abuse |
|
|
|
| 22 Apr 2016 09:52 AM |
You want a script that organizes the models in the workspace or in a table?
#code if not toBool(RbxDev) then print("I'll get there one day!") end |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 11:48 AM |
In a workspace :)
Thanks for replying |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 11:50 AM |
| I want to order a undefined amount of models in an order based on values* |
|
|
| Report Abuse |
|
|
|
| 22 Apr 2016 11:57 AM |
try using table.sort()
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 12:18 PM |
| I understand but how do you make the loop finding the values? |
|
|
| Report Abuse |
|
|
|
| 22 Apr 2016 12:20 PM |
Place it model in a table, and loop through the table and get the value from the model. Use the value to re-arrange the Models in the table.. And CFrame it in a loop through the table using the order.
#code if not toBool(RbxDev) then print("I'll get there one day!") end |
|
|
| Report Abuse |
|
|
|
| 22 Apr 2016 01:32 PM |
Assuming all models have the same parent..
local models = MODEL_PARENT:GetChildren() table.sort(model, function(a, b) return a.Value.Value < b.Value.Value end) -- The 'models' table now contain the models in order from least Value to most Value |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 02:03 PM |
| And if I want to loop it in a script in the StarterGui ? How do I refer to the model in the workspace.[Name].Buildings? |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 22 Apr 2016 05:14 PM |
Maybe everything is not clear, I'll try and explain it again. I have 3 models in workspace.game.buildings Each model has a number value and a picture I am making a script in the StarterGui. Is there a code which loops through an undefined amount of models and finds the corresponding value and orders it (in a table )? Then I want to show a list of pictures based on the order of the table (StarterGui ).
I just started programming and not everything is clear yet. Thanks for the help in advance!
|
|
|
| Report Abuse |
|
|
|
| 22 Apr 2016 05:19 PM |
Ok having the context makes it easier to write the code.
local models = MODEL_PARENT:GetChildren() table.sort(models, function(a, b) return a.Value.Value < b.Value.Value end) -- The 'models' table now contain the models in order from least Value to most Value
-- Assuming the ID value is the asset ID of the image... for i, v in pairs(models) do -- v is the current model in the loop, going from least Value to most Value -- Assume i is the index and you label your picture frames in your GUI SOMEIMAGEGUI.Image = "rbxassetid://" .. v.ID.Value end |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 23 Apr 2016 07:00 AM |
Thanks for replying very quickly. I still have some problems.
I have 3 models workspace.game.buildings.model1 -workspace.game.buildings.model1.ItemID -workspace.game.buildings.model1.ThumbnailID
workspace.game.buildings.model2 -workspace.game.buildings.model2.ItemID -workspace.game.buildings.model2.ThumbnailID
workspace.game.buildings.model3 -workspace.game.buildings.model3.ItemID -workspace.game.buildings.model3.ThumbnailID
I am working in startersgui.script which creates a screengui
imageLabel[first position in table, Value].Image = "rbxassetid://[first position in table, ThumbnailID]" imageLabel[second position in table, Value].Image = "rbxassetid://[second position in table,ThumbnailID]" till all models are looped
What do I have to fill in for MODEL_PARENT and SOMEIMAGEGUI?
Sorry for the many questions, thanks for helping! |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 01:06 PM |
| Honestly, it would be easier if you just gave us the source of your StarterGui script or a picture of the hierarchy of the ScreenGui that gets created. |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 23 Apr 2016 03:19 PM |
local screenGui = Instance.new("ScreenGui") screenGui.Parent = script.Parent This? |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 03:33 PM |
theres 2 types of searching and reading that I like using. It seems like you want some sort of GUI Catalog, so I'd put every item under a dictionary like this:
ids= { Candy={model=workspace.Candy,id=1}, Sport={model=workspace.Sport,id=2} }
then iterate through the list like this whenever you wish to retrieve an ordered list. you can add models and whatnot to the list with varying ids, they dont have to be in order.
function catapairs(tab)
-- store the name of every sub table local key = {} for name in pairs(tab) do key[#key+1]=name end
--sort the name table we created table.sort(key, function(n1,n2) return tab[n1].id < tab[n2].id end)
-- return the iteration function used to display the list local keynum = 0 return function() keynum = keynum + 1 if key[keynum] then -- returns the key table entry, then the ordered ID table. return key[keynum], tab[key[keynum]] end end end
so if you want to iterate something like a sorted list you'd do
for key,value in catapairs(ids) do -- where key variable is the name of the table and value is the pointer for the table! end |
|
|
| Report Abuse |
|
|
hrhr7777
|
  |
| Joined: 15 Aug 2014 |
| Total Posts: 9 |
|
|
| 25 Apr 2016 03:33 PM |
| Okay thanks for replying! I will try figuring it out |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2016 03:35 PM |
A new shortcut.. Instead of doing Instance.new you could do... #code Create = LoadLibrary("RbxUtility").Create --To spawn a part for instance.. Create("Part"){ Name = "Yo man..."; Parent = game.Workspace }
#code if not toBool(RbxDev) then print("I'll get there one day!") end |
|
|
| Report Abuse |
|
|