I’m currently working on creating a turn based game. I have a player with a state machine and an enemy with a state machine. On the player script I have a variable called player turn, and obviously after every action or state the player has performed the player.playerturn variable is set to false so that he can no longer perform actions until the variable is changed back, I thought that I could just change the variable back to true when the enemy has completed an action but for some reason it just doesn’t change? I’ve set up the player script as a Global, but I’m wondering if I should rather set up the entire player scene as an autoload? I tried to make the enemy scene an autoload but it just gave me errors saying that the path doesn’t hold a scene even though it does, and that the node count was equal to zero even though it clearly wasn’t.
I feel like I’m just not understanding the basic concepts of autoloads and singletons. If someone could please please give any advice, even if it’s just a summary of how autoloads and singletons work or how to autoload an entire scene, I will be so grateful!
I’m betting you have a player Scene with script and a Global with the same script. The Global is a Node on the root with your script, different from your player inside the scene with your script.
You probably do not want a Player Global/Autoload scene, instead you can give your player scene a group and use get_tree().get_first_node_in_group("Player") to get the active player.
You can check the “remote” tab of the scene tree while your game is running to see the in-game tree structure.
Sorry, I got one more question, it’s giving me problems when I try declare a variable and set it to the get_tree.get_first_node etc. I have the player group but when I try type get_tree the auto complete suggests get_stack and not get_tree, am I missing smth here?
hmm that seems to have worked but only partly, I’m still not able to change the value of player turn to be true. Just also as more context, I’m trying to change the value of the player turn variable, which is inside the script on the player scene and player group, by setting it equal to true when a state has been exited on the enemy state machine INSIDE the enemy scene, not as apart of the enemy script and node itself.