Lua Basics

From Cheat Engine
Revision as of 19:40, 5 February 2018 by FreeER (talk | contribs) (Cheat table lua script)
Jump to navigation Jump to search


Lua interaction is done a few ways in Cheat Engine.

  1. You have the Lua Engine that you can access from the memory view form by selecting tools then selecting lua engine.
    Tutorials.LuaBasics.01.png
  2. There is a lua script associated with your cheat table that you access form the Cheat Engine main form menu by selecting table then select show cheat table lua script. You can also load and execute other lua scripts.
    Tutorials.LuaBasics.02.png
  3. There is the luaCall Auto Assembler command, that you pass the Lua code to. You can open an auto assembler form from the Cheat Engine main form by pressing Ctrl+Alt+A.
    luaCall(print('I have the power!'))
  4. Then there is making use of the {$lua} tag in an Auto Assembler script. You can open an auto assembler form from the Cheat Engine main form by pressing Ctrl+Alt+A.
    Tutorials.LuaBasics.04.png
    There is also a memrec variable made for Auto Assembler scripts that are saved as memory records on a table.
{$lua}
if syntaxcheck then return end
print(memrec.Description)
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
------------------------------ DISABLE ------------------------------
[DISABLE]
if syntaxcheck then return end
Tutorials.LuaBasics.06.png


Lua Engine

Form the Cheat Engine main form press Shift+Ctrl+Alt+L to open the Lua Engine form. The Lua Engine form contains a text box for lua's standard output (print calls use the standard output) as well as an interactive script box that you can directly execute lua script. You can open or save scripts from here.

Tutorials.LuaBasics.03.png


Cheat table lua script

From the Cheat Engine main form press Ctrl+Alt+L, to open the cheat table lua script form.

Tutorials.LuaBasics.05.png

This script is associated with the cheat table. By default when opening a cheat table file Cheat Engine will prompt you that the table has a table lua script and asking you if you want to execute it.

Note: You can change what Cheat Engine does with the cheat table Lua script in the Cheat Engine general settings.

From the cheat table lua script form menu you can select file then select new window to open new 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 lua's require, which will only run a script the first time it's required, and dofile, which will run a script every time you call it. Note that you do not use the extension with require, ".lua" is assumed, but you do need it with dofile.

Code:

require('Script1') dofile('Script1.lua') require('Script1')

Output:

Script1 Executing... Script1 Executing...


See also

External links

Syntax Highlighter