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 


String interpolation in lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
chandest
Newbie cheater
Reputation: 0

Joined: 27 Feb 2013
Posts: 17

PostPosted: Sun Oct 30, 2022 6:43 am    Post subject: String interpolation in lua Reply with quote

I was wondering, is it possible to use string interpolation when using `readInteger`?

Code:

local myValue = readInteger("[[[mygame.exe-00000104]+DB4]+3C]+B48")


I would love to use variables here, e.g.:

Code:

local offs0 = "DB4"
local offs1 = "3C"
local offs2 = "B48"
local myValue = readInteger("[[[mygame.exe-00000104]+offs0]+offs1]+offs2")


Perhaps this is very lua specific? Does anyone have something nice implemented already?

EDIT:

Seems something like this goes:

Code:

local var0 = "mygame.exe-00000104"
local var1 = "DB4"
local var2 = "3C"
local var3 = "B48"
local addy = string.format("[[[%s]+%s]+%s]+%s", var0, var1, var2, var3)

_________________
The king is dead. Long live the king!
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Sun Oct 30, 2022 4:00 pm    Post subject: Reply with quote

Try searching google, eg.
http://lua-users.org/wiki/StringInterpolation
http://lua-users.org/wiki/VarExpand
http://lua-users.org/wiki/TextTemplate
https://github.com/hishamhm/f-strings
https://stackoverflow.com/questions/58058777/use-variables-inside-a-string-in-lua
also check other google results.

One twist if apply in AA script, we may have to check the value type and if it is number type and integer, we may need to convert to hexadecimal string instead of just tostring, like some html template that some html escaping/un-escaping may be need.

_________________
- Retarded.
Back to top
View user's profile Send private message
Y.A.K.E
Advanced Cheater
Reputation: 0

Joined: 15 Jul 2019
Posts: 51

PostPosted: Tue Nov 08, 2022 11:13 am    Post subject: Reply with quote

yes.
local addr
addr = getAddrss(addy)
or
addr = getAddressSafe(addy)

if (addr ~=nil and addr ~= 0) then
local myValue = readInteger(addr)
else
print("addr is null")
end
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