Lua:Class:Component

From Cheat Engine
Jump to navigation Jump to search

{} Class

class Component : Object

The Component class is the base class for Lua-exposed components.

Components can own other components and provide a name, tag value, owner reference, and access to their child components.

Inheritance[edit]

Class Inherits From Description
Component Object Base class for Lua-exposed components.
Object None Base class for Lua-exposed objects.

Properties[edit]

Property Type Description
ComponentCount Integer The number of child components. Read-only.
Component[index] Component Array containing the child components. The index starts at 0. Read-only.
ComponentByName[name] Component Returns a child component by name. Read-only.
Name String The name of the component.
Tag Integer Free-to-use integer storage space. Useful for IDs or custom state.
Owner Component The owner of this component. Nil if it has no owner.

Methods[edit]

Method Return Type Description
getComponentCount() Integer Returns the number of components attached to this component.
getComponent(index) Component Returns the child component at the specified index.
findComponentByName(name) Component Returns the child component with the specified name.
getName() String Returns the component name.
setName(newname) void Changes the component name.
getTag() Integer Returns the component tag value.
setTag(tagvalue) void Sets the component tag value.
getOwner() Component Returns the owner of this component.

Examples[edit]

Read the component count[edit]

1 local form = createForm(false)
2 
3 createButton(form)
4 createLabel(form)
5 
6 print("ComponentCount: " .. tostring(form.ComponentCount))
7 print("getComponentCount(): " .. tostring(form.getComponentCount()))
8 
9 form.destroy()

Access child components by index[edit]

 1 local form = createForm(false)
 2 
 3 local button = createButton(form)
 4 button.Name = "ButtonA"
 5 
 6 if form.ComponentCount > 0 then
 7   local component = form.Component[0]
 8   print(component.Name)
 9 end
10 
11 form.destroy()

Enumerate child components[edit]

 1 local form = createForm(false)
 2 
 3 createButton(form).Name = "ButtonA"
 4 createLabel(form).Name = "LabelA"
 5 
 6 for i = 0, form.ComponentCount - 1 do
 7   local component = form.getComponent(i)
 8   print(i .. ": " .. component.Name)
 9 end
10 
11 form.destroy()

Find a component by name[edit]

 1 local form = createForm(false)
 2 
 3 local button = createButton(form)
 4 button.Name = "ApplyButton"
 5 
 6 local byProperty = form.ComponentByName["ApplyButton"]
 7 local byMethod = form.findComponentByName("ApplyButton")
 8 
 9 print(byProperty == byMethod)
10 
11 form.destroy()

Read and change the component name[edit]

 1 local form = createForm(false)
 2 local button = createButton(form)
 3 
 4 button.Name = "OldName"
 5 
 6 print(button.getName())
 7 
 8 button.setName("NewName")
 9 
10 print(button.Name)
11 
12 form.destroy()

Use Tag as custom integer storage[edit]

 1 local form = createForm(false)
 2 local button = createButton(form)
 3 
 4 button.Tag = 1001
 5 print(button.Tag)
 6 
 7 button.setTag(2002)
 8 print(button.getTag())
 9 
10 form.destroy()

Get the owner of a component[edit]

 1 local form = createForm(false)
 2 local button = createButton(form)
 3 
 4 local owner = button.Owner
 5 
 6 if owner == button.getOwner() then
 7   print("Owner: " .. tostring(owner.Name))
 8 end
 9 
10 form.destroy()

Check whether a component has an owner[edit]

1 local form = createForm(false)
2 local button = createButton(form)
3 
4 if button.getOwner() ~= nil then
5   print("The button has an owner")
6 end
7 
8 form.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Form Related Classes