How do you check to see if a value of an address has changed?

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Reclaimer Shawn
Novice Cheater
Novice Cheater
Posts: 18
Joined: Fri Feb 23, 2018 9:41 am
Reputation: 2

How do you check to see if a value of an address has changed?

Post by Reclaimer Shawn »

Let's say I want to have a function execute whenever a certain address value changes from one value to another(let's say address 0x80000000). I've tried setting readInteger("80000000") as a variable and then comparing it to itself, but that doesn't appear to work. How could I changing of an address via Lua?

TimFun13
Expert Cheater
Expert Cheater
Posts: 1354
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 6

Re: How do you check to see if a value of an address has changed?

Post by TimFun13 »

Not real sure but some thing like this might work, and the synchronized thread part is only needed if you want to mess with stuff on the UI thread.

Code: Select all

{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
local address = 0x80000000
local function synchronizedLuaThread(thread)
	if RunLuaThread then
		-- Body for UI code.
	end
	checkSynchronize()
	if thread ~= nil and type(thread.terminate) == 'function' then
		thread.terminate()
	end
end
local function luaThread(thread)
	while RunLuaThread do
		if readInteger(address) ~= LuaThreadLastValue then
			LuaThreadLastValue = readInteger(address)
			-- Body for non-UI code.
			synchronize(synchronizedLuaThread)
		end
		sleep(0)
	end
	thread.terminate()
end
----------------------------------
if syntaxcheck then return end
RunLuaThread = true
LuaThreadLastValue = readInteger(address)
createThread(luaThread)
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
RunLuaThread = false
LuaThreadLastValue = nil

Reclaimer Shawn
Novice Cheater
Novice Cheater
Posts: 18
Joined: Fri Feb 23, 2018 9:41 am
Reputation: 2

Re: How do you check to see if a value of an address has changed?

Post by Reclaimer Shawn »

ShyTwig16 wrote:
Sat Mar 24, 2018 8:04 pm
Not real sure but some thing like this might work, and the synchronized thread part is only needed if you want to mess with stuff on the UI thread.
Thanks for trying to help me, but I wasn't able to understand how to implement the above code. However, I ended up solving my issue anyways. I'd asked this because I needed to check whenever things in the game met a certain condition, and then set values based on that. I instead found an address that flags whenever the thing I wanted to record happened, and that was enough to do what I wanted. Thanks once again though!

Post Reply

Who is online

Users browsing this forum: No registered users