Datatable

From GMod Wiki

Jump to: navigation, search

A datatable is a structure that is fed to the SENT and SWEP lists. A datatable consists of the following elements (these are number indexed, starting at 1):

A datatable_header structure. This determines the labelling of the buttons above the list. Typically this isn't changed much.

This is a single datatable entry. There should be a corresponding value to each value on the datatable_header - so, if you have 5 columns, you should have 5 values on the datatable row. In addition, a console command is required for each datatable_row. See the article for more details.

You can add as many datatable rows as you want after the datatable_header.

A datatable is written like so:

 
--Our datatable
local datatable={}
 
--Create header and add it first
local header={}
header[1]="Column 1"
header[2]="Column 2"
header[3]="Column 3"
 
table.insert(datatable,header)
 
 
--Create 20 rows and add them
for i=0,20 do
    local row={}
    row[1]="Row "..i..", column 1"
    row[2]="Row "..i..", column 2"
    row[3]="Row "..i..", column 3"
 
    row.command="do_command "..i
 
    table.insert(datatable,row)
end
 
--Assuming this is in a function it should be returned
return datatable
 
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox