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 


Lua Script Cheat Table -- The Best Way

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
CritixIO
How do I cheat?
Reputation: 0

Joined: 23 Mar 2025
Posts: 2

PostPosted: Sun Mar 23, 2025 8:05 pm    Post subject: Lua Script Cheat Table -- The Best Way Reply with quote

Your 'Lua Script : Cheat Table' got so much lines of codes ? this is not a problem anymore !

The better way is to load '.lua' files directly inside the Cheat Table, there is an exemple :

1: Make the directories of your .lua files where you want
Image1 --> i.postimg.cc/m2rRWpXX/Image2.jpg

2 : Load all lua files inside 'Lua Script : Cheat Table'
Image2 --> i.postimg.cc/CL3Cpkvt/Image1.jpg

3 : Use a great text editor like 'Sublime Text'
Image3 --> i.postimg.cc/2yxCCPhy/Image3.jpg

4: Enjoy it in Auto-Assemble Script
Image4 --> i.postimg.cc/DZPqKwjX/Image4.jpg

PS : I found a little bug with this tricks, if you define in .lua file a 'local' outside a function, cheatengine will return a nil value if you try to get it (this is why i set GNames, GObjects and Version in the last image).

I hope Dark Byte know why and can tell us if this can be patched or not


sorry for images, that was a beautifull post but can't use url's :/
images host used : postimages.org
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Mar 23, 2025 8:45 pm    Post subject: Reply with quote

Quote:
PS : I found a little bug with this tricks, if you define in .lua file a 'local' outside a function, cheatengine will return a nil value if you try to get it (this is why i set GNames, GObjects and Version in the last image).

I hope Dark Byte know why and can tell us if this can be patched or not


That is not a bug, that is how 'scope' works within Lua.

The 'visibility' of variables is dependent on where they are defined, and in what manner they are defined (ie. global vs. local). Lua treats anything not prefixed with 'local' as a global value which can be accessible from anywhere, even if its defined in a secondary script and accessed with 'require'.

For example:
Code:

-- Place inside of b.lua:
test_value = 1234;

-- Place inside of a.lua:
require 'b.lua';
print(test_value);


Running 'a.lua' in this setup will print '1234' because the variable 'test_value' was defined into the global space.

If you edit 'b.lua' and place a 'local' keyword in front of 'test_value', then the variable is no longer a global and is instead 'local' to the scope of the 'b.lua' script. That means only the script itself can access the value. Other scripts that 'require' it will not be able to access it.

It is always best to avoid defining global variables and 'polluting' the global space. If you need to share data between scripts then you can return a table from a script that can be accessed when another script requires it. An example of that looks like this:

Code:

-- Place inside of b.lua:
local t = {};

t.test_value = 1234;

return t;


-- Place inside of a.lua:
local b = require 'b';

print(b.test_value);


Which should print '1234'.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
CritixIO
How do I cheat?
Reputation: 0

Joined: 23 Mar 2025
Posts: 2

PostPosted: Sun Mar 23, 2025 8:54 pm    Post subject: Reply with quote

atom0s wrote:
Quote:
PS : I found a little bug with this tricks, if you define in .lua file a 'local' outside a function, cheatengine will return a nil value if you try to get it (this is why i set GNames, GObjects and Version in the last image).

I hope Dark Byte know why and can tell us if this can be patched or not


That is not a bug, that is how 'scope' works within Lua.

The 'visibility' of variables is dependent on where they are defined, and in what manner they are defined (ie. global vs. local). Lua treats anything not prefixed with 'local' as a global value which can be accessible from anywhere, even if its defined in a secondary script and accessed with 'require'.

For example:
Code:

-- Place inside of b.lua:
test_value = 1234;

-- Place inside of a.lua:
require 'b.lua';
print(test_value);


Running 'a.lua' in this setup will print '1234' because the variable 'test_value' was defined into the global space.

If you edit 'b.lua' and place a 'local' keyword in front of 'test_value', then the variable is no longer a global and is instead 'local' to the scope of the 'b.lua' script. That means only the script itself can access the value. Other scripts that 'require' it will not be able to access it.

It is always best to avoid defining global variables and 'polluting' the global space. If you need to share data between scripts then you can return a table from a script that can be accessed when another script requires it. An example of that looks like this:

Code:

-- Place inside of b.lua:
local t = {};

t.test_value = 1234;

return t;


-- Place inside of a.lua:
local b = require 'b';

print(b.test_value);


Which should print '1234'.



Thanks for the share i'm new to learn lua, it's my 2nd day, normaly i code in C# and it's totally different than Lua from what i see lol, i understand now Smile
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 36

Joined: 16 Feb 2017
Posts: 1511

PostPosted: Sun Mar 23, 2025 11:09 pm    Post subject: Re: Lua Script Cheat Table -- The Best Way Reply with quote

CritixIO wrote:
PS : I found a little bug with this tricks, if you define in .lua file a 'local' outside a function, cheatengine will return a nil value if you try to get it (this is why i set GNames, GObjects and Version in the last image).

I hope Dark Byte know why and can tell us if this can be patched or not


So, not "local", just give and define the local itself.

In the first example below, "local" is used as you said;

file.lua:
Code:
local val = 1000

function multiple(s1,s2)
  if tonumber(s1) and tonumber(s2) then
     return tonumber(s1) * tonumber(s2)
  end
end

function addition(s1,s2)
  if tonumber(s1) and tonumber(s2) then
     return tonumber(s1) + tonumber(s2)
  end
end

function fullprog(s1)
  if s1 then
     loadstring("res = "..s1)()
     return res
  end
end


script load code:
Code:
local proc1 = findTableFile('file.lua').stream
proc1 = load(readStringLocal(proc1.memory,proc1.size))()

res = fullprog(11 * 100)
print(1,res) ---------------> 1 1100

res = addition(11, val)
print(2,res)  ---------------> 2

res = multiple(11, 100)
print(3,res) ---------------> 3 1100


( When not using "local" ..)
file.lua:
Code:
val = 1000 ----> no local ..

function multiple(s1,s2)
  if tonumber(s1) and tonumber(s2) then
     return tonumber(s1) * tonumber(s2)
  end
end

function addition(s1,s2)
  if tonumber(s1) and tonumber(s2) then
     return tonumber(s1) + tonumber(s2)
  end
end

function fullprog(s1)
  if s1 then
     loadstring("res = "..s1)()
     return res
  end
end


script load code:
Code:
local proc1 = findTableFile('file.lua').stream
proc1 = load(readStringLocal(proc1.memory,proc1.size))()

res = fullprog(11 * 100)
print(1,res) ---------------> 1 1100

res = addition(11, val)
print(2,res)  ---------------> 2 1011

res = multiple(11, 100)
print(3,res) ---------------> 3 1100

_________________
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