Hello, I'm working on a frogger clone for a personal project to learn godot. I've hit an issue while working on global variables, they won't assign their new value to anything.

What I set is that the Global script checks the current difficulty (which goes up after a certain amount of levels) and a function in the global script runs through some ifs and elifs to set the enemy speed and number. Why I'm asking for help is that what is assigned by the function is not used when the speed and number variables are called globally by other scripts.

Github link to current code (issues with Global and enemyArray scripts) https://github.com/manpaka/debugRepo/tree/main/froggerv1/scripts

I have the difficultly (gameStates) function set in the global script as to keep the amount of code in the enemy instances low, and I'm still trying to clean it up from the grid based movement that was set before.

Could you add some print statements to your code that demonstrate a Global variable being set to a value, and a different value being gotten from the variable?

I looked through the code, and I see a few things wrong but I'm not sure if that is your problem.

First, the Global script is running every frame (on process) when you should just call that function on level changes or on some event (when the difficulty increases), and not every frame.

Also, these are not the same thing:

print(Global.enemylvl)
print(units)

The first line should get the actual global variable, the second line gets a copy (whenever you initialized the variable) and it will never update. If you are working with global variables, you always need to access them through the class name (Global in your case) otherwise you will be assigning a new value to a copy, which isn't what you want.

Otherwise, I'm not sure. Can you post a small section of the code here that you think isn't working, or let me know what the print statements say? Also, maybe just zip up the whole project folder and upload it somewhere (like Google Drive) so I can test and take a look.

I took gameStates function out of process and into the win function in the player script and now it seemingly works.

I've also just made the Enemy Array to just directly use the enemylvl variable per the mention of how the units variable takes a copy of enemylvl.

I just need to add a level transition and work on the details a bit more, and I'll have finally finished this project. Thank you for the advice and help.

Also if you want to look at it more here's a zip file of the project folder https://drive.google.com/file/d/1ZtklcbAU_SY5x-3Q9ccBpmKGT6xoqJEb/view?usp=sharing

2 years later