Property Fields (get/set variables)
Property Fields provide a way to control access to script or class fields, offering more flexibility than simple variables. They are defined by specifying read and write access identifiers within parentheses after the field name.
Here is a basic Property Field usage example:
./songs/script1.hx
public var myvar(default, set):Int;
function set_myvar(val:Int):Int {
if(val > 10) return myvar = val;
return val;
}
./songs/[SONG NAME]/scripts/script2.hx
function create() {
myvar = 20; // This will trigger the set call stored on the field.
}
More information about property fields here.
Particularities
As of writing this, this system presents some limitations. For example:
(get, null)
or(null, set)
has no effect for writing nor reading, it acts like (get, default).- Calling the get/set function directly will trigger that function twice due to accessing the property field on call (if is a real variable, like
(get, null)
or(default, set)
). For example, calling directlyset_myvar
will call the same function again when tries to write onmyvar
. Avoid doing this unless you have a full property field (a non-real variable, i.e.(get, set)
or(get, never)
). This will be fixed in the future.
Written by: Jamextreme140
Last updated: 2025-09-12