Lua Basics

From Cheat Engine
Revision as of 23:59, 11 December 2011 by Jgoemat (talk | contribs)
Jump to navigation Jump to search

LUA interaction is done two main ways in Cheat Engine. First you have the Lua Engine window which you access from "Tools->Lua Engine" (or CTRL+L) in the Memory Viewer, second is a LUA script associated with your cheat table that you access by "Table->Show Cheat Table Lua Script" (or CTRL+ALT+L) from the main window. You can also load and execute other scripts.

Lua Engine

From the memory viewer, hit CTRL+L to open the Lua Engine window. The Lua Engine window contains the Output of all of your scripts (from print() calls) as well as an interactive script box to let you execute commands. File:LuaEngine1.png

Cheat Table Lua Script

From the main Cheat Engine window, click on "Table->Show Cheat Engine Lua Script". This script is associated with your cheat table. When you open your cheat table you will get a message box informing you that your table has a script associated with it and asking you if you want to execute it. From here you can click File->New Window to open other script windows.

Script Windows

You can have as many script windows open as you want. If you save these scripts as .LUA files in the same directory as your cheat table, you can run them from other scripts using the functions "require" which will only run a script the first time and "dofile" which will run a script every time you call it. Note that you do not use the extention with require, ".lua" is assumed, but you do need it with dofile:

-- test script
print ("Script2 Executing...")
print ("Calling require...")
require("Script1")
print ("Calling dofile...")
dofile("Script1.lua")
print ("Calling require...")
require("Script1")
print ("Calling dofile...")
dofile("Script1.lua")

Output (require calls not shown because it had already been run):

Script2 Executing... 
Calling require... 
Calling dofile... 
Script1 Executing... 
Calling require... 
Calling dofile... 
Script1 Executing...