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
Cheater
Cheater
Posts: 26
Joined: Fri Feb 23, 2018 9:41 am
Reputation: 1

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

Post by Reclaimer Shawn » Sat Mar 24, 2018 7:51 pm

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?

User avatar
TheyCallMeTim13
Administration
Administration
Posts: 984
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 155
Contact:

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

Post by TheyCallMeTim13 » 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.

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
Cheater
Cheater
Posts: 26
Joined: Fri Feb 23, 2018 9:41 am
Reputation: 1

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

Post by Reclaimer Shawn » Sun Mar 25, 2018 12:58 am

TheyCallMeTim13 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