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 


Hex,dec calculator

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Fri Jul 30, 2021 8:48 am    Post subject: Hex,dec calculator Reply with quote

Code:
function calcHex(value)
hexOffset = string.format('0x%X',value);
print(hexOffset)
end

function calcDec(value)
decOffset = string.format('%d',value)
print(decOffset)
end

I can't use function calcDec like this 'calcDec(BC)'
And help me with the form please(i'm trying to make dec,hex calculator window)



Hex Calculator.LUA
 Description:
File

Download
 Filename:  Hex Calculator.LUA
 Filesize:  391 Bytes
 Downloaded:  136 Time(s)

Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1051
Location: 0x90

PostPosted: Fri Jul 30, 2021 12:34 pm    Post subject: Reply with quote

It's not necessary to have a calcDec function use tonumber([hex value])

example:
Code:

local x = 0xA
print(tonumber(x))
--Should print 10 to console


But, if you insist on using your own function. The error is that you failed to prepend "0x" to the value passed to the calcDec function like so:

Code:

calcDec(0xA)


Fully working functions here and example of usage.

Code:

function calcHex(value)
hexOffset = string.format('0x%X',value);
print(hexOffset)
return hexOffset
end

function calcDec(value)
decOffset = string.format('%d', value);
print(decOffset)
return decOffset
end

function calcHexAddress(addr,value)
hexAddr = (string.format("%X", addr + value))
print(hexAddr)
return hexAddr
end

function calcDecAddress(addr,value)
decAddr = string.format('%d', addr + value)
print(decAddr)
return decAddr
end


calcHex(10)                     -- A
calcDec(0xFF)                   -- 255
calcHexAddress(0x400000,0xBEEF) -- 40BEEF
calcDecAddress(0x400000,0xBEEF) -- 4243183
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