Skip to content
shadow7483147 edited this page Jul 21, 2020 · 15 revisions

Syntax

Tables and Arrays are used to store variables into an ordered, accessible type of variable. They make up a special case of variable access and assignment.

Arrays are functionally similar to tables, in particular being slightly more efficient, but they cannot store arrays or tables themselves, and do not have string key indices.

Syntax Description
TableVar["test",bone] This will return the value at the table's "test" string key, with the explicit type "bone"
TableVar[4,bone] This will return the value at the table's 4th numeric index, with the explicit type "bone"
TableVar[8,vector] = Vec This assigns the variable Vec to TableVar's 8th index.
VarArray["beef",vector] = Vec This assignment is invalid, as arrays do not have string keys.

Shared functions

Below is a function list from the Table core and Array core extensions. Any functions that are supported only by either an array or a table are listed further down below.

Function Return Example Print
T:concat([S,N,N]) T=table(2,3), T["a",number]=4, print(T:concat()) 23
Concatenates the elements of the table/array's numeric indices to a string in order.
Optionally, a string delimiter may be used, which separates the concatenated elements in the returned string. You may also define the index to start at, and an index to end at, inclusively.
Starts at index 1 by default. Nonexistent consecutive elements will concatenate to the string "nil".
T:concat()
A:concat()
T=table(2,3), T["a",number]=4, print(T:concat()) 23
Concatenates the elements of the table/array's numeric indices to a string.

Lookup Tables

A common optimization trick using Tables involves the use of T:exists() to check if a table contains a string key . This avoids having to do long elseif chains to find one particular string in a set of referenced strings.

For example, say you have an E2 door that only allows people on your friends list. How do know who to let through the door?
We'll add yourself in to start.

Table = table()
Table["STEAM_0:0:0",number] = 1
The element in this case doesn't really matter, since we only need the string key. Now if you want to add anyone to your friends list, you can add their Steam ID as a key to the table just as easily,
Table[Player:steamID(),number] = 1
and reference them later more efficiently.
local ID = Target:steamID()
if(Table:exists(ID)){
    Door:open()
}
You can even do neat tricks like returning different values for different keys. Just in case you wanted to have a list of people your doorside turret will automatically set to kill.
if(!Table[ID,number]){
    if(TargetModeNeutral & Table:exists(ID)){ #Check if we have the target on the blacklist (0 return on steamID)
        Turret:shootAt(Target:pos())
    }elseif(!TargetModeNeutral){ #We're not neutral, target everyone that isn't our friend.
        Turret:shootAt(Target:pos())
    } #else do nothing
}

Expression 2 ⚛️

Tutorials (In learning order) 🎓

Extras ❔

Tools 🛠️

Click To Expand

Advanced

Beacon 💡

Control 🎛️

Data 💿

Detection 👀

Display 💻

Render

I/O 🔌

Physics 🚀

Utilities 🛠️

RFID

Wireless 🛜

Gates 🚥

Click To Expand

TBD

Clone this wiki locally