Difference between revisions of "Lua:readBytes"

From Cheat Engine
Jump to navigation Jump to search
m
m (Syntax Highlighting.)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' readBytes(''Address'', ''ByteCount'', [''ReturnAsTable''])
+
{{CodeBox|'''function''' readBytes(''Address'', ''ByteCount'', [''ReturnAsTable''])}}
  
 
Reads bytes from the specified address in the currently opened (target) process.   
 
Reads bytes from the specified address in the currently opened (target) process.   
Line 26: Line 26:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
-- Read 4 bytes and get them as separate values
 
-- Read 4 bytes and get them as separate values
 
local b1, b2, b3, b4 = readBytes(0x123456, 4)
 
local b1, b2, b3, b4 = readBytes(0x123456, 4)
Line 36: Line 36:
 
   print("Byte " .. i .. ": " .. v)
 
   print("Byte " .. i .. ": " .. v)
 
end
 
end
</pre>
+
</syntaxhighlight >
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
 
 
{{ReadWriteMemory}}
 
{{ReadWriteMemory}}

Latest revision as of 15:26, 25 June 2026

<> Lua API Reference

function readBytes(Address, ByteCount, [ReturnAsTable])

Reads bytes from the specified address in the currently opened (target) process. Returns the bytes as multiple return values or as a table if ReturnAsTable is true.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in the target process to read from.
ByteCount Integer The number of bytes to read.
ReturnAsTable Boolean (optional) If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.

Examples[edit]

1 -- Read 4 bytes and get them as separate values
2 local b1, b2, b3, b4 = readBytes(0x123456, 4)
3 print(b1, b2, b3, b4)
4 
5 -- Read 4 bytes and get them as a table
6 local bytes = readBytes(0x123456, 4, true)
7 for i, v in ipairs(bytes) do
8   print("Byte " .. i .. ": " .. v)
9 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine