Lua:saveTable

From Cheat Engine
Revision as of 19:01, 25 June 2026 by Leunsel (talk | contribs) (Major overhaul of the post.)
Jump to navigation Jump to search

<> Lua API Reference

function saveTable(filename, protect OPTIONAL, dontDeactivateDesignerForms OPTIONAL) : void

<> Lua API Reference

function saveTable(stream, dontDeactivateDesignerForms OPTIONAL) : void

Saves the current Cheat Engine table.

saveTable can save the table to a file path or to a stream object. When saving to a filename with the .CETRAINER extension, the optional protect parameter can be used to protect the trainer from being read normally.

Function Parameters

Parameter Type Description
filename String The path where the current table should be saved. Usually this is a .CT or .CETRAINER file.
stream Stream A stream object the current table should be saved to.
protect Boolean OPTIONAL Only used by the filename overload. If true and filename has the .CETRAINER extension, the trainer is protected from being read normally.
dontDeactivateDesignerForms Boolean OPTIONAL If true, designer forms are not deactivated while saving the table.

Returns

This function does not return a value.

Description

saveTable saves the currently loaded Cheat Engine table.

When called with a filename, Cheat Engine writes the current table to disk. When called with a stream, Cheat Engine writes the table data to the given stream object.

The protect parameter only applies to the filename overload and is intended for protected .CETRAINER output.

Save Modes

Call Behavior
saveTable(filename) Saves the current table to a file.
saveTable(filename, protect) Saves the current table to a file and optionally protects .CETRAINER output.
saveTable(filename, protect, dontDeactivateDesignerForms) Saves the current table to a file with explicit protection and designer-form behavior.
saveTable(stream) Saves the current table to a stream object.
saveTable(stream, dontDeactivateDesignerForms) Saves the current table to a stream object with explicit designer-form behavior.

Examples

Save the current table as a CT file

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

Save the current table as a CETRAINER file

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

Save a protected CETRAINER file

1 saveTable([[C:\\CheatTables\\protected.cetrainer]], true)

Save a table without deactivating designer forms

1 saveTable([[C:\\CheatTables\\example.ct]], false, true)

Ask the user where to save the table

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

Save only if the filename is valid

1 local filename = [[C:\\CheatTables\\backup.ct]]
2 
3 if filename ~= "" then
4   saveTable(filename)
5 end

Create a timestamped backup

1 local backupName = os.date([[C:\\CheatTables\\backup_%Y%m%d_%H%M%S.ct]])
2 
3 saveTable(backupName)

Save the current table to a MemoryStream

1 local stream = createMemoryStream()
2 
3 saveTable(stream)
4 
5 print("Saved bytes: " .. tostring(stream.Size))
6 
7 stream.destroy()

Save the current table to a stream and then to disk

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

Save to a stream without deactivating designer forms

1 local stream = createMemoryStream()
2 
3 saveTable(stream, true)
4 
5 print("Saved bytes: " .. tostring(stream.Size))
6 
7 stream.destroy()

Store the current table as an embedded table file

1 local stream = createMemoryStream()
2 
3 saveTable(stream)
4 stream.Position = 0
5 
6 local tableFile = createTableFile("backup.ct")
7 tableFile.Stream.copyFrom(stream, stream.Size)
8 
9 stream.destroy()

Replace an existing backup file

1 local filename = [[C:\\CheatTables\\backup.ct]]
2 
3 if fileExists(filename) then
4   deleteFile(filename)
5 end
6 
7 saveTable(filename)

Main Pages

Core Lua documentation entry points

Lua
Script Engine