Difference between revisions of "Lua:getAutoAttachList"

From Cheat Engine
Jump to navigation Jump to search
(added more details and examples)
(Major overhaul of the post.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' getAutoAttachList() ''':''' UserData ('''[[Lua:Class:StringList|StringList]]''')
+
{{CodeBox|'''function''' getAutoAttachList() ''':''' StringList}}
  
Returns Cheat Engine's global '''Auto Attach''' process list as a live [[Lua:Class:StringList|StringList]] object.
+
Returns the Auto Attach [[Lua:Class:Stringlist|Stringlist]] object.
  
* '''Parameters:''' <None>
+
The returned list contains process names that Cheat Engine can automatically attach to. The object can be controlled with the StringList routines and properties, but it should not be destroyed.
* '''Returns:''' A shared '''[[Lua:Class:StringList|StringList]]''' object containing process names that Cheat Engine will try to auto-attach to when they start.
 
** '''Ownership:''' ''Do not'' call '''destroy()''' on this object. It is owned by Cheat Engine and shared with the UI/settings.
 
  
 +
===Function Parameters===
 +
This function has no parameters.
  
=== Description ===
+
===Returns===
 +
[[Lua:Class:Stringlist|Stringlist]] — The Auto Attach string list object.
  
Cheat Engine can automatically attach to a process if its name appears in the Auto Attach list. This function exposes that list to Lua as a '''[[Lua:Class:StringList|StringList]]''', allowing you to:
+
===Examples===
  
* Inspect the current auto-attach targets
+
====Get the Auto Attach list====
* Add new process names (e.g., ''notepad.exe'')
+
<syntaxhighlight lang="lua" line highlight="1">
* Remove or clear entries
+
local autoAttachList = getAutoAttachList()
* Reorder items
 
  
Changes take effect immediately and are reflected in Cheat Engine's UI.
+
print("Auto Attach entries: " .. tostring(autoAttachList.Count))
 +
</syntaxhighlight>
  
 +
====Add a process name====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local autoAttachList = getAutoAttachList()
  
=== Function Parameters ===
+
autoAttachList.add("game.exe")
 +
</syntaxhighlight>
  
''None''
+
====Add a process name only if it is missing====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local autoAttachList = getAutoAttachList()
 +
local processName = "game.exe"
  
 +
if autoAttachList.IndexOf(processName) == -1 then
 +
  autoAttachList.add(processName)
 +
end
 +
</syntaxhighlight>
  
=== Returns ===
+
====Print all Auto Attach entries====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local autoAttachList = getAutoAttachList()
  
A live [[Lua:Class:StringList|StringList]] object. Common members you may use:
+
for i = 0, autoAttachList.Count - 1 do
 +
  print(autoAttachList[i])
 +
end
 +
</syntaxhighlight>
  
* '''Count''' — number of items
+
====Remove a process name====
* '''Add(text)''' — append a process name
+
<syntaxhighlight lang="lua" line highlight="1">
* '''Delete(index)''' — remove by index (0-based)
+
local autoAttachList = getAutoAttachList()
* '''IndexOf(text)''' — find an item's index or return -1 if not found
+
local index = autoAttachList.IndexOf("game.exe")
* '''Clear()''' — remove all items
 
* '''Strings[index]''' / '''[index]''' — get/set item text
 
  
''Reminder:'' This is a shared internal object. Do not destroy it.
+
if index ~= -1 then
 +
  autoAttachList.delete(index)
 +
end
 +
</syntaxhighlight>
  
 +
====Clear the Auto Attach list====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local autoAttachList = getAutoAttachList()
  
=== Usage Examples ===
+
autoAttachList.clear()
 +
</syntaxhighlight>
  
'''Simple Auto Attach to a Process:'''
+
====Set multiple Auto Attach entries====
* See [[Tutorials:Lua:Setup_Auto_Attach|Setup Auto Attach Tutorial]] for more details.
+
<syntaxhighlight lang="lua" line highlight="1">
getAutoAttachList().add("mygame.exe")
+
local autoAttachList = getAutoAttachList()
  
'''Print the current auto-attach list:'''
+
autoAttachList.clear()
local list = getAutoAttachList()
+
autoAttachList.add("game.exe")
for i = 0, list.Count - 1 do
+
autoAttachList.add("game_dx12.exe")
  print(i .. ": " .. list[i])
+
autoAttachList.add("game_win64_shipping.exe")
end
+
</syntaxhighlight>
  
'''Add a new target (if not already present):'''
+
====Use Text to replace the list====
local list = getAutoAttachList()
+
<syntaxhighlight lang="lua" line highlight="1">
local name = "notepad.exe"
+
local autoAttachList = getAutoAttachList()
if list.IndexOf(name) == -1 then
 
  list.Add(name)
 
  print("Added: " .. name)
 
else
 
  print("Already exists: " .. name)
 
end
 
  
'''Get the name of the second auto-attach target:'''
+
autoAttachList.Text = [[game.exe
getAutoAttachList().getString(1)
+
game_dx12.exe
 +
game_win64_shipping.exe]]
 +
</syntaxhighlight>
  
'''Remove a target by name:'''
+
====Check whether a process is in the Auto Attach list====
local list = getAutoAttachList()
+
<syntaxhighlight lang="lua" line highlight="1">
local name = "oldgame.exe"
+
local autoAttachList = getAutoAttachList()
local idx = list.IndexOf(name)
 
if idx ~= -1 then
 
  list.Delete(idx)
 
  print("Removed: " .. name)
 
end
 
 
 
'''Clear all entries (use with care):'''
 
local list = getAutoAttachList()
 
list.Clear()
 
print("Auto-attach list cleared. Count = " .. list.Count)
 
 
 
'''Insert and reorder:'''
 
local list = getAutoAttachList()
 
-- Insert at the top
 
list.Insert(0, "game.exe")
 
-- Move first item to the end
 
if list.Count > 0 then
 
  local first = list[0]
 
  list.Delete(0)
 
  list.Add(first)
 
end
 
 
 
 
 
=== Notes ===
 
 
 
* Entries are typically process executable names (e.g., ''game.exe'').
 
* The list is shared with Cheat Engine's UI; edits here show up in the Auto Attach configuration.
 
* ''Don't'' call '''destroy()''' on the returned list. Manage entries via standard '''StringList''' methods.
 
  
 +
if autoAttachList.IndexOf("game.exe") ~= -1 then
 +
  print("game.exe is in the Auto Attach list")
 +
end
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
* [[Lua:Class:StringList|StringList]]
 
```
 

Latest revision as of 19:52, 25 June 2026

<> Lua API Reference

function getAutoAttachList() : StringList

Returns the Auto Attach Stringlist object.

The returned list contains process names that Cheat Engine can automatically attach to. The object can be controlled with the StringList routines and properties, but it should not be destroyed.

Function Parameters[edit]

This function has no parameters.

Returns[edit]

Stringlist — The Auto Attach string list object.

Examples[edit]

Get the Auto Attach list[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 print("Auto Attach entries: " .. tostring(autoAttachList.Count))

Add a process name[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 autoAttachList.add("game.exe")

Add a process name only if it is missing[edit]

1 local autoAttachList = getAutoAttachList()
2 local processName = "game.exe"
3 
4 if autoAttachList.IndexOf(processName) == -1 then
5   autoAttachList.add(processName)
6 end

Print all Auto Attach entries[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 for i = 0, autoAttachList.Count - 1 do
4   print(autoAttachList[i])
5 end

Remove a process name[edit]

1 local autoAttachList = getAutoAttachList()
2 local index = autoAttachList.IndexOf("game.exe")
3 
4 if index ~= -1 then
5   autoAttachList.delete(index)
6 end

Clear the Auto Attach list[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 autoAttachList.clear()

Set multiple Auto Attach entries[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 autoAttachList.clear()
4 autoAttachList.add("game.exe")
5 autoAttachList.add("game_dx12.exe")
6 autoAttachList.add("game_win64_shipping.exe")

Use Text to replace the list[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 autoAttachList.Text = [[game.exe
4 game_dx12.exe
5 game_win64_shipping.exe]]

Check whether a process is in the Auto Attach list[edit]

1 local autoAttachList = getAutoAttachList()
2 
3 if autoAttachList.IndexOf("game.exe") ~= -1 then
4   print("game.exe is in the Auto Attach list")
5 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine