Fake Protected Variables
With the setget
keyword’s power, you can protect your variables from being used outside of the class your variables are created from.
extends Node
class_name Animals
var _protectedVar:String = "Protected Variable" setget protectedSet, protectedGet
func protectedSet(param1):
print('Can\'t Access Private Variable Setter')
func protectedGet():
print('Can\'t Access Private Variable Getter')
By creating a setter and getter method that neither changes the value of the variable nor returns back its value, you will have created a variable in which no other class has access to its value.
Resources
Github Project:
Godot Tutorials Resources