Skip to content

Documentations

Jurian / Lucy edited this page Oct 17, 2020 · 8 revisions

Installation

Getting this module isn't really the most challenging. There are several ways you could do this.

  1. downloading the code from here
  2. Pulling the github repo (in case you work in Visual Studio Code) and using it as any other normal module
  3. Obtaining the free model which can be acquired here

Functionality Documentation

SmartTables.new(<Table> target, <string> reference name, <boolean> shared)

Description
creates a new smart table allowing for quick searching through it.

Parameters

Variable name Type Description
target table The template of which the smart table will take the base from to create a more easier to use table functionality
reference name string This is an optional variable, if left empty it will default to a randomly generated string. only really applies to when the table is shared
shared boolean this boolean defaults to false, if set to true other scripts of the same permission layer can access the storage to modify or read the table (server on itself or client on itself)

Returns

Variable name Type Description
Init_Metatable Metatable Can be used to have simplistic control over your table.

SmartTables.GetTable(<string> Name)

Description
Returns the shared smart table that's affiliated with the given name, if any.

Parameters

Variable name Type Description
Name string The name of one of the shared smart tables.

Returns

Variable name Type Description
Smart_Metatable Metatable Can be used to have simplistic control over your table.

Smart_Metatable:GetRaw()

Description
Returns the raw table from the point entry. In this case the full table without any metatables inserted.

Returns

Variable name Type
Raw_table table

Smart_Metatable:getn()

Description
Returns the table count (not descendant count) of the table, regardless of if this table is a dictionary, array or a mix. similar to #Table

Returns

Variable name Type
Count int

Smart_Metatable:Dispose()

Description
Disposes the full smart table. An empty table will remain on the initial smart table's variable, that variable would need to be manually disposed by setting it to nil (or simply by doing Init_Metatable = Init_Metatable:Dispose())

Smart_Metatable["ValueName"]

Description
This is a special indexation, by indexing anything that's below the Init_Metatable it will return the value of the given ValueName. Examples can be found here. It's basically a recursive search.

Returns

Variable name Type
Smart_Metatable Metatable

Creation & Instantiation

in order to require and create a smart table simply follow the next couple steps. Firstly, lets define a random table with random values as example

local TempTable = {
    Table445 = {
        Table21 = {
            Table2 = {
                Table3 = {
                    Meh = {
                        TargetTable = {
                            Table5 = {
                                Secondary = {
                                    Value = 256
                                }
                            }
                        },
                    }
                }
            }
        };
        Table45 = {
            Value = 7;
        };
        {
            Value23 = 2;
        }
    }
}

awesome, that should work for reference. Next up, create the new smart table (you can also just write out the table inside the smart table)

local SmartTables = require("SmartTableLocation") -- replace "SmartTableLocation" with the hierarchy reference to the table
local Table = SmartTables.new(TempTable)

But wait... Didn't we see 2 other parameters given at .new()? As a matter of fact, there were. These 2 variables are optional and default to something if not filled in. They are used to determine the table as shared for all the other scripts, just as module scripts work. so how do we do that instead? Simple;

local SmartTables = require("SmartTableLocation") -- replace "SmartTableLocation" with the hierarchy reference to the table
local Table = SmartTables.new(TempTable, "SomeTable", true)

that's it, you can easily call this table from a different script with

local SmartTables = require("SmartTableLocation") -- replace "SmartTableLocation" with the hierarchy reference to the table
local Table = SmartTables.GetTable("SomeTable")

So, going into the functionality of what and how. We used a really, really big table and we want to get to value within Secondary and not to value within table45. This is how you easily get to that value AND are able to set it in the same way too

print(Table.Secondary.Value) -- outputs 256
Table.Secondary.Value = 5
print(Table.Table5.Value) -- outputs 5, used a different table in between to show that it replicates over just like tha

That's it. literally. in terms of optimization additions to your code eventually, please do read the documentations carefully and apply dispose properly where needed.

BEWARE storing a table segment in a new variable will make a "copy" from that variable. you will need to dispose these separately through that variable.

local SmartTables = require("SmartTableLocation") -- replace "SmartTableLocation" with the hierarchy reference to the table
local Table = SmartTables.new(TempTable)

local Table5 = Table.Table5
Table = Table:Dispose()
Table5 = Table5:Dispose()

The fun thing here is, any value adjusted copies over without any issue. however when the initial table is disposed and you remain with a copy, the copy will still live on as it's own segment!