Difference between revisions of "Lua:loadTable"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
m
 
Line 159: Line 159:
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 +
 +
{{CheatTable}}

Latest revision as of 19:05, 25 June 2026

<> Lua API Reference

function loadTable(filename, merge OPTIONAL) : void

<> Lua API Reference

function loadTable(stream, merge OPTIONAL, ignoreluascriptdialog OPTIONAL) : void

Loads a Cheat Engine table file.

loadTable can load a table from a file path or from a stream object. It supports .CT tables and .CETRAINER files. When merge is true, the currently loaded table is kept and the loaded table is merged into it.

Function Parameters[edit]

Parameter Type Description
filename String The path to the .CT or .CETRAINER file to load.
stream Stream A stream object containing the table data to load.
merge Boolean OPTIONAL If true, the loaded table is merged into the current table. If false or omitted, the current table is cleared before loading.
ignoreluascriptdialog Boolean OPTIONAL Only used by the stream overload. If true, the Lua script warning/dialog can be ignored when loading the table.

Returns[edit]

This function does not return a value.

Description[edit]

loadTable loads a Cheat Engine table into the current Cheat Engine session.

When called with a filename, Cheat Engine loads the table directly from disk. When called with a stream, Cheat Engine reads the table data from the given stream object.

The merge parameter controls whether the existing address list is cleared:

merge Behavior
false or omitted The current table is cleared before the new table is loaded.
true The new table is merged into the currently loaded table.

Examples[edit]

Load a table from disk[edit]

1 loadTable([[C:\\CheatTables\\example.ct]])

Load a trainer from disk[edit]

1 loadTable([[C:\\CheatTables\\example.cetrainer]])

Merge a table into the current table[edit]

1 loadTable([[C:\\CheatTables\\extra_records.ct]], true)

Replace the current table explicitly[edit]

1 loadTable([[C:\\CheatTables\\main.ct]], false)

Ask the user for a table file[edit]

1 local dialog = createOpenDialog(nil)
2 
3 dialog.Filter = "Cheat Engine Tables (*.CT)|*.CT|Cheat Engine Trainers (*.CETRAINER)|*.CETRAINER|All files (*.*)|*.*"
4 
5 if dialog.execute() then
6   loadTable(dialog.FileName)
7 end
8 
9 dialog.destroy()

Load a table from a MemoryStream[edit]

1 local stream = createMemoryStream()
2 
3 stream.loadFromFile([[C:\\CheatTables\\example.ct]])
4 stream.Position = 0
5 
6 loadTable(stream)
7 
8 stream.destroy()

Merge a table from a MemoryStream[edit]

1 local stream = createMemoryStream()
2 
3 stream.loadFromFile([[C:\\CheatTables\\extra_records.ct]])
4 stream.Position = 0
5 
6 loadTable(stream, true)
7 
8 stream.destroy()

Load from a stream and ignore the Lua script dialog[edit]

1 local stream = createMemoryStream()
2 
3 stream.loadFromFile([[C:\\CheatTables\\scripted_table.ct]])
4 stream.Position = 0
5 
6 loadTable(stream, false, true)
7 
8 stream.destroy()

Load an embedded table file[edit]

1 local tableFile = findTableFile("extra_records.ct")
2 
3 if tableFile ~= nil then
4   local stream = tableFile.getData()
5 
6   stream.Position = 0
7   loadTable(stream, true)
8 end

Safe helper for loading a table[edit]

 1 local function loadTableIfExists(path, merge)
 2   if fileExists(path) then
 3     loadTable(path, merge or false)
 4     return true
 5   end
 6 
 7   return false
 8 end
 9 
10 if not loadTableIfExists([[C:\\CheatTables\\main.ct]]) then
11   print("Table file does not exist")
12 end

Load multiple tables into one session[edit]

1 loadTable([[C:\\CheatTables\\base.ct]], false)
2 loadTable([[C:\\CheatTables\\extras.ct]], true)
3 loadTable([[C:\\CheatTables\\debug.ct]], true)

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Cheat Table Related Functions