Difference between revisions of "Lua:findTableFile"
(Major overhaul of the template.) |
|||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' findTableFile(''filename'') ''':''' | + | {{CodeBox|'''function''' findTableFile(''filename'') ''':''' TableFile}} |
| − | Returns a [[Lua:Class:TableFile|TableFile]] object | + | Returns a [[Lua:Class:TableFile|TableFile]] object for a file stored inside the current cheat table. |
| − | + | ||
| + | A table file is embedded in the cheat table itself. It can be used directly by functions that accept table files, such as [[Lua:playSound|playSound]], or accessed as a stream through the [[Lua:Class:TableFile|TableFile]] object. | ||
===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 | ||
| Line 13: | Line 14: | ||
|filename | |filename | ||
|String | |String | ||
| − | |The name of the file | + | |The name of the file stored in the cheat table. |
|} | |} | ||
| − | == | + | ===Returns=== |
| − | + | [[Lua:Class:TableFile|TableFile]] — The table file object with the given name. | |
| − | + | ||
| + | If no table file with that name exists, the function returns nil. | ||
| + | |||
| + | ===Description=== | ||
| + | findTableFile searches the files embedded in the current cheat table and returns the matching [[Lua:Class:TableFile|TableFile]] object. | ||
| + | |||
| + | This is useful when a script needs to access resources that were packaged with the cheat table, such as sounds, images, binary data, or other support files. | ||
| + | |||
| + | ===Examples=== | ||
| + | |||
| + | ====Play an embedded sound==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("protected.wav") | ||
| + | |||
| + | if file ~= nil then | ||
| + | playSound(file) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | === | + | ====Check if a table file exists==== |
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| − | To add a file to your table, open the 'Table' menu and | + | if file == nil then |
| + | print("The table file was not found") | ||
| + | else | ||
| + | print("The table file exists") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save an embedded file to disk==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | file.saveToFile([[C:\\Temp\\data.bin]]) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Load a table file into a MemoryStream==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | local stream = createMemoryStream() | ||
| + | |||
| + | file.Stream.Position = 0 | ||
| + | stream.copyFrom(file.Stream, file.Stream.Size) | ||
| + | |||
| + | print("Loaded bytes: " .. tostring(stream.Size)) | ||
| + | |||
| + | stream.destroy() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Use a table file as script resource==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local function requireTableFile(filename) | ||
| + | local file = findTableFile(filename) | ||
| + | |||
| + | if file == nil then | ||
| + | error("Missing table file: " .. filename) | ||
| + | end | ||
| + | |||
| + | return file | ||
| + | end | ||
| + | |||
| + | local sound = requireTableFile("protected.wav") | ||
| + | |||
| + | playSound(sound) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Adding a File to the Table=== | ||
| + | To add a file to your table, open the '''Table''' menu and choose '''Add File'''. | ||
[[Image:AddFile.png]] | [[Image:AddFile.png]] | ||
| − | + | Select the file you want to embed. Cheat Engine adds it to the table using the original filename. | |
| − | + | ||
| − | you can rename it, save it | + | After the file has been added, it appears as a separate entry below '''Add file''' in the '''Table''' menu. From there, you can rename it, save it to disk, or delete it. |
[[Image:AddedFileMenu.png]] | [[Image:AddedFileMenu.png]] | ||
| + | ===Common Uses=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Use Case | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |Sounds | ||
| + | |Store sound files in the table and play them with [[Lua:playSound|playSound]]. | ||
| + | |- | ||
| + | |Images | ||
| + | |Store image resources that can be loaded by GUI scripts. | ||
| + | |- | ||
| + | |Binary resources | ||
| + | |Store binary data that a Lua script can read or extract. | ||
| + | |- | ||
| + | |Support files | ||
| + | |Package helper files with the table instead of requiring separate files on disk. | ||
| + | |} | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Revision as of 18:52, 25 June 2026
Returns a TableFile object for a file stored inside the current cheat table.
A table file is embedded in the cheat table itself. It can be used directly by functions that accept table files, such as playSound, or accessed as a stream through the TableFile object.
Contents
Function Parameters
| Parameter | Type | Description |
|---|---|---|
| filename | String | The name of the file stored in the cheat table. |
Returns
TableFile — The table file object with the given name.
If no table file with that name exists, the function returns nil.
Description
findTableFile searches the files embedded in the current cheat table and returns the matching TableFile object.
This is useful when a script needs to access resources that were packaged with the cheat table, such as sounds, images, binary data, or other support files.
Examples
Play an embedded sound
1 local file = findTableFile("protected.wav")
2
3 if file ~= nil then
4 playSound(file)
5 end
Check if a table file exists
1 local file = findTableFile("data.bin")
2
3 if file == nil then
4 print("The table file was not found")
5 else
6 print("The table file exists")
7 end
Save an embedded file to disk
1 local file = findTableFile("data.bin")
2
3 if file ~= nil then
4 file.saveToFile([[C:\\Temp\\data.bin]])
5 end
Load a table file into a MemoryStream
1 local file = findTableFile("data.bin")
2
3 if file ~= nil then
4 local stream = createMemoryStream()
5
6 file.Stream.Position = 0
7 stream.copyFrom(file.Stream, file.Stream.Size)
8
9 print("Loaded bytes: " .. tostring(stream.Size))
10
11 stream.destroy()
12 end
Use a table file as script resource
1 local function requireTableFile(filename)
2 local file = findTableFile(filename)
3
4 if file == nil then
5 error("Missing table file: " .. filename)
6 end
7
8 return file
9 end
10
11 local sound = requireTableFile("protected.wav")
12
13 playSound(sound)
Adding a File to the Table
To add a file to your table, open the Table menu and choose Add File.
Select the file you want to embed. Cheat Engine adds it to the table using the original filename.
After the file has been added, it appears as a separate entry below Add file in the Table menu. From there, you can rename it, save it to disk, or delete it.
Common Uses
| Use Case | Description |
|---|---|
| Sounds | Store sound files in the table and play them with playSound. |
| Images | Store image resources that can be loaded by GUI scripts. |
| Binary resources | Store binary data that a Lua script can read or extract. |
| Support files | Package helper files with the table instead of requiring separate files on disk. |

