Just replacing the order of things seemed to resolve some of the issues, but then I got stuck a bit at Enemy instance to Turrets is below Turrets.Variable(Range). I typed a manual value instead (e.g. 500) and then it started working.
So, I went to write the value of Turrets.Variable(Range) as a text value on-screen for debugging, and found that distance for Turret1 type was 300 ,and Turret2 0 (should be 500 for both). Of course the distance can’t be smaller than 0, so Turret2 type will never shoot.
These are the defaults defined in Gdevelop editor, however, I also define the actual desired values in “At the beginning of the scene” in the External event for TurretControl attached to each level. (this handles all turret related stuff). The reason for this is so that when I make new levels (e.g. Scene2,Scene3, etc. for maps) I won’t have to recopy the objects each time some of their variables are changed (e.g. if I changed turret1range in map editor in scene1, I would also have to manually change it in scene2 and scene3, or however many scenes exist at that moment). I’m sure external layouts can also be used so that I only have one object of each type which is called (and I will consider this), but this seemed like a simple enough method, and I wanted to have the ability to manually place some objects for each map in the visual editor.
I tried assigning values like this:
(Okay, the insane amount of repetitions on Event #3 is just for testing purposes to make sure it’s not something related to timing of execution).
But to my surprise, the value of Range is still written out as 300, which is the “initial value” set in Gdevelop object variables editor. Turret2’s Range was declared but set to 0 by default (I didn’t add a custom initial value), since I expected the event to change that to the desired value, but since it was still reading 0 as range, it would never shoot, obviously.
If I remove the “at the beginning of the scene” condition, and just leave “Do =500 to variable Range of Turret2” then it does work, but of course, I don’t want this value to constantly be assigned, instead it should be once on scene beginning.
I’ve considered that maybe I cannot have multiple external events all having “At the beginning of the scene”, or multiple conditions “at the beginning of the scene” in the same scene. if you know of such an issue, please let me know. However, “Pause the current animation” and “do… to animation frame” work properly, and they are in the same condition.
I’m fairly certain that I don’t have additional code which modifies the variable Range later on and causes this issue (I have not yet implemented any saving/loading of stats and upgrade functionality, that comes later).
Do you have any idea what might cause this? It might be something very obvious which I’m missing.