Hi! This is my first post. I've been playing flare for about a year now. I really like the game, and I think you've done an amazing work. I don't have much programming experience, but flare has motivated me to try to learn C++, just so that I can understand the engine. Anyways, I found a quirky bug and I think I've fixed it, but I'm not 100% sure about the solution, so please tell me what you think.
The bug
The bug has something to do with the save_onload attribute. More specifically, it occurs when you set the save_onload attribute to false and then you try to start a new game that has an initial cutscene.
Here is how to replicate it.
1) Go to /flare-game/mods/empyrean_campaign/engine
2) Open the file misc.txt with a text editor
3) Add the following line: save_onload=false
4) Save the file and close it.
5) Open flare and the Empyrean Campaign as you normally do, and create a new game.
What will happen after doing this is that the cutscene will run over and over again, as if it was caught in some sort of infinite loop.
Now let's take a look at the solution(s).
First solution
There are at least two solutions to this problem, as far as I can tell. The first one can be done without touching the C++ code. The second one requires some small adjustments to the source code. Let's see the first one:
1) Go to /flare-game/mods/empyrean_campaign/maps
2) Open the file arrival.txt with a text editor
3) Delete the following lines:
[event]
# backstory cutscene
type=event
location=17,17,1,1
activate=on_load
cutscene=cutscenes/backstory.txt
requires_not_status=empyrean_backstory
set_status=empyrean_backstory
4) Save the file and close it.
5) Run flare, Empyrean Campaign, as you would normally do. Create a new game and start playing.
This first solution is not very convenient. By doing this you can play the game with save_onload set to false, but... you don't have a cutscene anymore. So let's take a look at the second solution:
Second solution
1) Go to /flare-engine/src
2) Open the file GameStatePlay.cpp with a text editor (you don't need CodeBlocks or anything that powerful for this solution, any simple text editor such as GEdit will suffice for our purposes here)
3) Go to the following part:
if (eset->misc.save_onload)
save_load->saveGame();
4) Don't do anything to the preceding lines; instead add the following lines beneath them:
if (!eset->misc.save_onload)
save_load->saveGame();
Notice the "!" sign in the preceding lines. What we are doing here, as far as I can tell, is saying that if the attribute save_onload has been set to false in the miscellaneous engine settings, then it should still be possible to save the game under some other conditions to be specified at a later stage by the modder (for example, by saving the game when your character rests at a tavern or something, using the event.save_game attribute).
5) Save the GameStatePlay.cpp file and close it.
6) Open a terminal, compile the game with cmake as you would normally do, then run flare, Empyrean Campaing, start a new game.
This second solution allows you to have save_onload set to false and still have a cutscene, avoiding that quirky infinite loop. However, I have to make some comments here. Obviously it's not very elegant, it's a copy-paste solution that only adds a "!" sign. This is why I didn't post this on the flare github. This little piece of code could be written more elegantly, but I just wanted to see if this copy-paste solution could solve the bug. I think it has, but I'm not 100% sure if this affects other parts of the engine's source code, so I don't know if this change to the engine is trivial or not. I'm assuming it is, but I thought it would be better to ask.
One last comment. When you replicate the bug, you will get two error messages, one from FileParser and one from SaveLoad (the SaveLoad error in particular will give you a warning, which says "Warning! Engine version of save file (0.0) does not match current engine version (1.10.06). Be on the lookout for bugs."
Despite those error messages, this bug has nothing to do with either FileParser or SaveLoad (I think), only with GameStatePlay, which, instead, will not inform you of any errors.
Am I on the right track here, or am I way off?
EDIT= I forgot to mention, in misc.txt, I also have save_onexit set to false. (I'm working on a mod where both save_onload and save_onexit are disabled. I have no idea if this has any effect on the bug or the proposed solutions)
Thanks for the thorough bug report! Though it is undesirable behavior in this case, it technically isn't a bug. Allow me to explain the flow based on the status of save_onload:
save_onload=true
save_onload=false
It is possible to fix this by adding 'save_game=true' to the cutscene event. That way the save will be triggered even if save_onload=false.
However, I think it's worth going a step further. I've added another property to misc.txt called 'save_oncutscene'. As the name implies, it globally controls saving the game when a cutscene is triggered. The default value is true to avoid "bugs" like this one, but modders can set it to false if they want to control game saves via events like in the above fix. The new property is available in v1.11.06.
Nice! I see that save_oncutscene is a bool type set to true by default, and that in GameStatePlay.cpp, it allows save_load to point to saveGame(). So there was no need to use the logical negation operator. A very elegant solution, and a new attribute! : )