Difference between revisions of "Lua:saveTable"
Jump to navigation
Jump to search
(Created page with 'Category:Lua '''function''' saveTable(''fileName'', ''protect'' OPTIONAL) Saves the current table. If protect is provided and set to true and the filename has the ".CETRAINE…') |
m |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' saveTable('' | + | {{CodeBox|'''function''' saveTable(''filename'', ''protect'' OPTIONAL, ''dontDeactivateDesignerForms'' OPTIONAL) ''':''' void}} |
| − | Saves the current table. | + | {{CodeBox|'''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=== | ===Function Parameters=== | ||
| − | {|width="85%" cellpadding="10 | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
!style="width: 80%;background-color:white;" align="left"|Description | !style="width: 80%;background-color:white;" align="left"|Description | ||
|- | |- | ||
| − | | | + | |filename |
|String | |String | ||
| − | |The | + | |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 | |protect | ||
| − | |Boolean | + | |Boolean OPTIONAL |
| − | |If | + | |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=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Call | ||
| + | !style="width: 80%;background-color:white;" align="left"|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 == | + | ===Examples=== |
| − | < | + | |
| − | saveTable( | + | ====Save the current table as a CT file==== |
| − | </ | + | <syntaxhighlight lang="lua" line> |
| − | < | + | saveTable([[C:\\CheatTables\\example.ct]]) |
| − | saveTable( | + | </syntaxhighlight> |
| − | </ | + | |
| + | ====Save the current table as a CETRAINER file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | saveTable([[C:\\CheatTables\\example.cetrainer]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save a protected CETRAINER file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | saveTable([[C:\\CheatTables\\protected.cetrainer]], true) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save a table without deactivating designer forms==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | saveTable([[C:\\CheatTables\\example.ct]], false, true) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Ask the user where to save the table==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local dialog = createSaveDialog(nil) | ||
| + | |||
| + | dialog.Filter = "Cheat Engine Tables (*.CT)|*.CT|Cheat Engine Trainers (*.CETRAINER)|*.CETRAINER|All files (*.*)|*.*" | ||
| + | dialog.DefaultExt = "ct" | ||
| + | |||
| + | if dialog.execute() then | ||
| + | saveTable(dialog.FileName) | ||
| + | end | ||
| + | |||
| + | dialog.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save only if the filename is valid==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local filename = [[C:\\CheatTables\\backup.ct]] | ||
| + | |||
| + | if filename ~= "" then | ||
| + | saveTable(filename) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Create a timestamped backup==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local backupName = os.date([[C:\\CheatTables\\backup_%Y%m%d_%H%M%S.ct]]) | ||
| + | |||
| + | saveTable(backupName) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save the current table to a MemoryStream==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createMemoryStream() | ||
| + | |||
| + | saveTable(stream) | ||
| + | |||
| + | print("Saved bytes: " .. tostring(stream.Size)) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save the current table to a stream and then to disk==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createMemoryStream() | ||
| + | |||
| + | saveTable(stream) | ||
| + | |||
| + | stream.Position = 0 | ||
| + | stream.saveToFile([[C:\\CheatTables\\stream_saved.ct]]) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save to a stream without deactivating designer forms==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createMemoryStream() | ||
| + | |||
| + | saveTable(stream, true) | ||
| + | |||
| + | print("Saved bytes: " .. tostring(stream.Size)) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Store the current table as an embedded table file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createMemoryStream() | ||
| + | |||
| + | saveTable(stream) | ||
| + | stream.Position = 0 | ||
| + | |||
| + | local tableFile = createTableFile("backup.ct") | ||
| + | tableFile.Stream.copyFrom(stream, stream.Size) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Replace an existing backup file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local filename = [[C:\\CheatTables\\backup.ct]] | ||
| + | |||
| + | if fileExists(filename) then | ||
| + | deleteFile(filename) | ||
| + | end | ||
| + | |||
| + | saveTable(filename) | ||
| + | </syntaxhighlight> | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | + | {{CheatTable}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 19:05, 25 June 2026
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.
Contents
- 1 Function Parameters
- 2 Returns
- 3 Description
- 4 Save Modes
- 5 Examples
- 5.1 Save the current table as a CT file
- 5.2 Save the current table as a CETRAINER file
- 5.3 Save a protected CETRAINER file
- 5.4 Save a table without deactivating designer forms
- 5.5 Ask the user where to save the table
- 5.6 Save only if the filename is valid
- 5.7 Create a timestamped backup
- 5.8 Save the current table to a MemoryStream
- 5.9 Save the current table to a stream and then to disk
- 5.10 Save to a stream without deactivating designer forms
- 5.11 Store the current table as an embedded table file
- 5.12 Replace an existing backup file
Function Parameters[edit]
| 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[edit]
This function does not return a value.
Description[edit]
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[edit]
| 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[edit]
Save the current table as a CT file[edit]
1 saveTable([[C:\\CheatTables\\example.ct]])
Save the current table as a CETRAINER file[edit]
1 saveTable([[C:\\CheatTables\\example.cetrainer]])
Save a protected CETRAINER file[edit]
1 saveTable([[C:\\CheatTables\\protected.cetrainer]], true)
Save a table without deactivating designer forms[edit]
1 saveTable([[C:\\CheatTables\\example.ct]], false, true)
Ask the user where to save the table[edit]
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[edit]
1 local filename = [[C:\\CheatTables\\backup.ct]]
2
3 if filename ~= "" then
4 saveTable(filename)
5 end
Create a timestamped backup[edit]
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[edit]
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[edit]
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[edit]
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[edit]
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[edit]
1 local filename = [[C:\\CheatTables\\backup.ct]]
2
3 if fileExists(filename) then
4 deleteFile(filename)
5 end
6
7 saveTable(filename)
Cheat Table Related Functions