Difference between revisions of "Tutorials:Lua:Basics"

From Cheat Engine
Jump to navigation Jump to search
Line 42: Line 42:
 
require("Script1")
 
require("Script1")
 
</pre> -->
 
</pre> -->
<p style="white-space:pre;font-family:'Lucida Console';display:block;overflow-x:auto;padding:0.5em;background:rgb(35, 36, 31);color:rgb(248, 248, 242);"><span style="color:rgb(166, 226, 46);">require</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1'</span>)</span>
+
<p style="line-height:1.15em;white-space:pre;font-family:'Lucida Console';display:block;overflow-x:auto;padding:0.5em;background:rgb(35, 36, 31);color:rgb(248, 248, 242);"><span style="color:rgb(166, 226, 46);">require</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1'</span>)</span>
 
<span style="color:rgb(166, 226, 46);">dofile</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1.lua'</span>)</span>
 
<span style="color:rgb(166, 226, 46);">dofile</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1.lua'</span>)</span>
 
<span style="color:rgb(166, 226, 46);">require</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1'</span>)</span>
 
<span style="color:rgb(166, 226, 46);">require</span><span style="color:rgb(248, 248, 242);">(<span style="color:rgb(230, 219, 116);">'Script1'</span>)</span>
Line 52: Line 52:
 
Script1 Executing...  
 
Script1 Executing...  
 
</pre> -->
 
</pre> -->
<p style="white-space:pre;font-family:'Lucida Console';display:block;overflow-x:auto;padding:0.5em;background:rgb(35, 36, 31);color:rgb(248, 248, 242);">Script1 Executing...  
+
<p style="line-height:1.15em;white-space:pre;font-family:'Lucida Console';display:block;overflow-x:auto;padding:0.5em;background:rgb(35, 36, 31);color:rgb(248, 248, 242);">Script1 Executing...  
 
Script1 Executing...  
 
Script1 Executing...  
 
</p>
 
</p>

Revision as of 09:09, 17 March 2017

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. 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


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+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