Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How do I LUA read a value and write a value?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
gaming04
Expert Cheater
Reputation: 0

Joined: 06 Dec 2010
Posts: 189

PostPosted: Sat Jun 14, 2025 11:21 am    Post subject: How do I LUA read a value and write a value? Reply with quote

I want to write a script where it takes a hotkey and then switches on a specific code where it reads a value and writes a new value when pressing the hotkey again.

1. Press hotkey; read values.
2. Press hotkey; does math to values and writes new values.

Is this how LUA works in CE? I have never understood how to use LUA in CE.

_________________
Life can be a blitz. What's right and wrong will fly right past you without you having to do a thing about it.

"Cheating only means you want to hold on to the things you value."
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 36

Joined: 16 Feb 2017
Posts: 1511

PostPosted: Sat Jun 14, 2025 5:07 pm    Post subject: Reply with quote

Isn't it easier to download the found address to the address list, select it, press enter and change the value?

If you want to test the value and change with Lua, here is some code to get you started.

Run the code (CE Lua Script >> Execute),
Press F4,
Type the address whose value you want to change in the opened dialog box and confirm.
Press F4 again,
Read the value and type the new value in the box and confirm.
To add another address, just put "-" (dash symbol) in the box and confirm.
Press F4 again and type the new address.


Code:
local addr = ""
local opt = 1

function addAddresses()
local res = ""
local str=inputQuery('Add Address!','Write: Address..', res)
  if str then
     addr = getAddress(str)
     opt = 2
  end
end

function readWriteValue()
  if addr=="" then
     addAddresses()
  else
     local val = readInteger(addr) or "?" or nil
     local res = ""
     local str=inputQuery('Replace Value',"Address: "..addr.."\nValue: "..val.."\n********************\n(Reset Address, write: -\nWrite: New value..", res)
     if str then
        if str=="-" then
           addr=""
           opt = 1
        else
           writeInteger(addr, str)
        end
     end
  end
end

function startKey()
sleep(150)
  if opt==1 then
     addAddresses()
  else
     readWriteValue()
  end
end

-- keys:
if addrKey1 then addrKey1.Destroy() addrKey1=nil end
addrKey1=createHotkey(startKey, VK_F4)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites