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 


Hexadecimal calculations in the edit box

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Sun Nov 17, 2019 6:05 pm    Post subject: Hexadecimal calculations in the edit box Reply with quote

How to perform hexadecimal calculations in the edit box? I want to perform hexadecimal calculations in the edit box with mouse wheel. Example:

Code:
local function incrvalhex(editbox)
if tonumber(editbox.Text) == nil then
editbox.Text ='00'
else
local a = tonumber(editbox.Text,16) +0x1
editbox.Text = string.format('0%X', a)
end
end

local function decrvalhex(editbox)
if tonumber(editbox.Text) == nil then
editbox.Text ='00'
else
local a = tonumber(editbox.Text,16) -0x1
editbox.Text = string.format('0%X', a)
end
end

MainForm.scanvalue.OnMouseWheelUp = function()
if MainForm.cbHexadecimal.Checked == true then
incrvalhex(MainForm.scanvalue)
end
end

MainForm.scanvalue.OnMouseWheelDown = function()
if MainForm.cbHexadecimal.Checked == true then
decrvalhex(MainForm.scanvalue)
end
end


But, the code above does not work. Where is the error in the code?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Nov 17, 2019 6:37 pm    Post subject: Reply with quote

Code:
local function changeHex(delta)
  if MainForm.cbHexadecimal.Checked then
    if MainForm.scanvalue.Text=='' then MainForm.scanvalue.Text='0' end
    local value = tonumber(MainForm.scanvalue.Text,16)+delta
    MainForm.scanvalue.Text = string.format('%016X',value)  -- leading zeros and length always 16 digits
  end
end

MainForm.scanvalue.OnMouseWheelUp = function() changeHex(-1) end
MainForm.scanvalue.OnMouseWheelDown = function() changeHex(1) end

_________________
Back to top
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 205

PostPosted: Sun Nov 17, 2019 7:26 pm    Post subject: Reply with quote

Thanks. I also want to add same function (OnMouseWheel Up\Down) to the "Change address" window to the address edit box (editAddress), but the problem is that the addresses there are displayed in two formats, in the format 009D874E and in the format "ePSXe.exe" + 5D874E. How to add +0x01 to this address "ePSXe.exe" + 5D874E ? So, after the “OnMouseWheelUp” event, the address will become “ePSXe.exe” + 5D874F or “OnMouseWheelDown” event, the address will become “ePSXe.exe” + 5D874D.
Back to top
View user's profile Send private message
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