 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 605
|
Posted: Tue Apr 14, 2026 5:27 pm Post subject: |
|
|
From a memscam I have a found address, memrec1 = 1041ebb4.
What i need to do is readSmallInteger(memrec1 +C). I believe that one just add C to the address, since it is a string. so some manipulations
| Code: |
memrec1 = 1041ebb4
memrec2 = tonumber(memrec1, 16)
memrec2 = memrec2 +12
hAddr = string.format('%x', memrec2)
hAddr= "0x" .. hAddr-- to obtain proper hex address
|
I get an error malformed number. This step is performed in the code without errors. Maybe the "immediate window" code handling if diffeent anyway I need a hex address +C to read the value. How am I to do thiis?
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 39
Joined: 16 Feb 2017 Posts: 1573
|
Posted: Thu Apr 16, 2026 2:28 am Post subject: |
|
|
The 'malformed number' error happens because of the way you are handling strings and hex prefixes in the immediate window or script.
In Cheat Engine Lua, readInteger or readSmallInteger functions prefer actual numbers (integers) as addresses.
You don't need to convert them back to strings or manually add '0x' before reading.
The Simple Way (Recommended)
You can do the math and the read operation in one line. Cheat Engine handles the hex notation 0xC automatically:
| Code: | local memrec1 = "1041ebb4"
local addr = tonumber(memrec1, 16) -- Convert string to number once
-- Now just add the offset and read. No string formatting needed!
local hpValue = readSmallInteger(addr + 0xC)
print(hpValue) |
Why your code failed:
Redundant Formatting:
When you did hAddr = "0x" .. hAddr, it became a string. If you pass a string to a math operation or some specific CE functions, Lua might fail to parse it if the format isn't perfect.
Immediate Window:
In the Lua Engine window, if you type 0x1041ebb4 + 0xC, it works instantly because Lua treats 0x... as a number literal.
Corrected logic for your script:
If you really need to see the address as a hex string for printing, do it after the calculation:
| Code: | local memrec1 = "1041ebb4"
local memrec2 = tonumber(memrec1, 16) -- The numeric base
-- 1. Do the math (Numeric)
local finalAddr = memrec2 + 0x0C
-- 2. Read the value (Using the number)
local value = readSmallInteger(finalAddr)
-- 3. Format only for display (String)
local hAddrStr = string.format('%X', finalAddr)
print("Reading from: " .. hAddrStr .. " Value: " .. value) |
Pro Tip: Always keep your addresses as numbers throughout your logic. Only convert them to strings at the very last second when you need to print() them or set them in the AddressList.
_________________
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 605
|
Posted: Sat Apr 18, 2026 1:10 pm Post subject: |
|
|
I knew it was a string but didn't realize that quotation marks needed to be added. To be clear when a memory scan finds an address: Lets say it was 1041ebb4 but that result is set to memrec1. To manipulate memscan1 I just used memscan without quotation marks why does this work awhile setting a param to 1041ebb4 failed?
BTW today when I firede up dosbox with wiz6 and ran my old recalculate without the second tier check of hp. A normal scan of memory found twelve addresses 12 addresses of the experience. At this game time all six heroes have identical experience. The recalculate set the first exp found along with gold to the first address found through the normal scan. Using the small bit of code you supplied at the end of the last post the hp was 89, correct and the second was also 89, so maybe different check would be in order, but the relearning comes first.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|