3.2 KiB
The Object class is the fundamental building block class in Basalt, from which all other objects and components are derived. You can think of it as the "origin" of all objects within the framework. The Object class provides essential functions that are common to all derived objects, such as adding and removing event listeners and managing inheritance and relationships between objects.
In simple terms, the Object class is like a common ancestor that passes down basic functions and properties to all subsequent objects. This makes it easier to keep the behavior of objects throughout the framework consistent and predictable.
| enable | Enables the event listeners |
| disable | Disables the event listeners |
| getType | Returns the object type |
| isType | Checks if the object is of a specific type |
| getName | Returns the name |
| getParent | Returns the parent |
| setParent | Changes the parent |
| getZIndex | Returns the z-index |
| remove | Removes the object from its parent |
Events
Events are actions or occurrences that happen during the execution of your program. In Basalt, objects can respond to various events, such as user interactions or changes in their properties. The following is a list of all available events for all objects:
| onClick | Fires when the object is clicked |
| onClickUp | Fires when the mouse button is released on the object |
| onRelease | Fires when the mouse button is released |
| onScroll | Fires when scrolling with the mouse wheel |
| onDrag | Fires when the object is being dragged |
| onHover | CraftOS-PC - fires when the mouse hovers over an object |
| onLeave | CraftOS-PC - fires when the mouse leaves an object |
| onKey | Fires when the object is focused and a keyboard key is pressed |
| onChar | Fires when the object is focused and a character key is pressed |
| onKeyUp | Fires when the object is focused and a keyboard key is released |
| onGetFocus | Fires when the object gains focus |
| onLoseFocus | Fires when the object loses focus |
| onEvent | Fires for any other event |
Sidenote: When you use return false, the object's event handler will be skipped. Here is an example of that.
This code would make it impossible to enter the letter 'a' into the input:
local basalt = require("basalt")
local main = basalt.createFrame()
local input = main:addInput()
:setPosition(3,3)
local function checkInput(self, event, char)
if(char=="a")then
return false
end
end
main:onChar(checkInput)
In this example, the checkInput function is defined to return false when the character 'a' is entered. When this occurs, the event handler for the input is skipped, preventing the letter 'a' from being added to the input.