Iâve pretty much established the foundation with the things above. The get/set really makes a difference when interacting with the database when searching for Enemy_ID, Furniture_ID, Player_IDs, etc.
Because when you change the data directly and use that same data in other classes, you donât have to apply signals or get references to everything. You directly use the same data and keep things simple.
I basically blind searched google and stumbled upon things that looked familiar. They looked similar enough to #C for me to understand. Things that are static are more efficient overall. My state machines use those static references that are organized to make things simple and clean.
class_name GameState
static var CurrentState : BaseState = TestState.new()
static func _ready():
CurrentState.Enter()
static func _physics_process(delta):
CurrentState.Update(delta)
static func ChangeState(newstate):
CurrentState.Exit()
CurrentState = newstate.new()
CurrentState.Enter()
This state machine is pretty simple and doesnât overcomplicate things. You are basically creating a variable and that holds an entire class inside. So instead of using switch statements you make a class instead.
class_name BaseState
func Enter():
# Perform Enter Animation
# Enable State Controls
pass
func Exit():
# Disable State Controls
# Perform Exit Animation
pass
func Update(delta):
# Called every frame.
# Delta is the elapsed time since the previous frame.
pass
Then you extend the entire class and use this for other states. As the states that extend from this, should share the exact same foundation. This makes sure youâre consistent with your code and makes things readable.
class_name TestState extends BaseState
var PlayerInput : bool = false
func Enter():
# Perform Enter Animations and Sounds
PlayerInput = true # Enable Controls
pass
func Exit():
PlayerInput = false # Disable Controls
# Perform Exit Animations and Sounds
pass
func Update(_delta):
if PlayerInput == true:
Move_Input()
Trigger_Input()
Action_Input()
func Move_Input():
pass
func Trigger_Input():
pass
func Action_Input():
pass
Here you will see my update function has three functions under a boolean if statement. The boolean makes sure that player input can be disabled at any time within this entire class.
Having the three functions like this helps organize the code, by splitting things up into bite size pieces. This way you can read and follow the code easier, because everything is separated into different categories.
func ChangeState():
GameState.ChangeState(TestState)
I can then use the static function to change my state from anywhere. The UI will basically use the get/set for information displayed. For example, when you change the health directly in the database. the UI automatically updates.
Unless you want the health to slowly trickle down. You then make a new variable in the UI and check to make sure theyâre equal. When theyâre not equal, you update every frame to slowly increase/decrease the UI_health until they are equal to the health in the Database.