|
| 08 Mar 2016 01:53 AM |
How would I have a table that constantly updates according to what children are inside a folder.
Example:
local inv script:FindFirstChild("Inventory")
invTable = {}
for i,v in pairs(inv:GetChildren()) do table.insert(invTable, v.Name) end
print(table.concat(invTable, ', '))
--//
How would I have the table be constantly updated by what children are present inside of the Inventory folder? I was thinking I could have it remove everything from the table, and add everything that's currently in the folder, every time the folder has a child added or removed. But is there an easier way?
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 01:58 AM |
Also, what's the function called to detect if a child has been added, removed, or changed?
~MightyDantheman |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 08 Mar 2016 01:59 AM |
You know, that's so pointless.
invTable = inv:GetChildren(); local function Update() local t = inv:GetChildren() for i=1,#invTable do invTable[i] = t[i] end; -- Or, invTable = inv:GetChildren() end; inv.ChildAdded:connect(Update); inv.ChildRemoved:connect(Update); |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 02:41 AM |
Wait, how would I make a GUI for the inventory? Would I have to make a scroll GUI and insert a new button for each item (by counting how many items exist in the inventory, and changing each one to match each item)?
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 03:13 AM |
Anyone know of a good tutorial video for an inventory system? The GUI part is confusing me.
~MightyDantheman |
|
|
| Report Abuse |
|
|
Fatul
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 254 |
|
|
| 08 Mar 2016 04:13 AM |
| One very inconsistent way would be to make several slots in a gui,then a loop to check and order things. |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 04:18 AM |
Here I will let you try a snapshot of my inventory system.
http://pastebin.com/DwxJtwbQ - Inventory http://pastebin.com/rJqyb3ss - Item http://pastebin.com/mQhAqLhK - Debug module, easy print stuff
How to use...
local Inventory = require("Inventory") local Item = require("Item")
local invy = Inventory.new(10) --allocate an inventory of 10 space invy[2] = Item.new(12, {})
The table {} is metadata specific to the item. With other versions, come different data structures. This is the only one I am leaking right now until my system is better. It is free and open source ofc.
With my inventory 2D class, it features
print(invy[{2,1}].Id) --> prints id of item in slot 2,1
It's pretty neat. |
|
|
| Report Abuse |
|
|