Button normalgraphic resets when restoring saved game

Started by WHAM, Thu 25/02/2021 19:54:56

Previous topic - Next topic

WHAM

Hopefully this is the right place for this, but I am observing a weird behaviour in AGS 3.5.0.
I use a button graphic to display some information, and just swap the buttons normalgraphic with code run when player changes rooms.
However, if the player saves the game, exits and loads the game, the button graphic defaults to the original default value given in the GUI settings for that button, rather than the state it should have been saved in.

Is this a feature or a bug in the AGS engine itself, or am I missing something here?
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

MaeveGlaistig

Same issue here!

I have a GUI that uses buttons to display a sort of "checklist" when the player succeeds at things. The buttons have an initial graphic that is just a transparent bar, and when the player succeeds at something, that action includes a little snippet to change the button's graphic to show it as done, like so:

Code: ags
    if (cCharacter.ActiveInventory == iKey)
    {  bBlessing.NormalGraphic = 411;  }


Where 411 is the sprite number of the correct new graphic. This works just fine! The weird part comes in when the game is saved and then restored from a saved game. Suddenly, the buttons have reverted to their previous transparent appearance... or so it seems. Actually, when they're moused over, the correct graphic populates, which makes it seem like something is preventing the saved game from remembering the button's new graphic until it is somehow interacted with. (For the record, these buttons aren't clickable - they don't do anything but display the graphic.)

What am I missing here? Is it something about changing the button's NormalGraphic property vs. something else I should be using instead?

MaeveGlaistig


Crimson Wizard

This is definitely a bug in the engine. GUI visual representation does not sync with actual data right after save is loaded, only when forced to by some event.

I think the temporary workaround may be to "tweak" gui a little in on_event with eEventRestoreGame, for example change it position by 1 pixel and back immediately.

WHAM

Quote from: Crimson Wizard on Fri 26/02/2021 06:11:03
This is definitely a bug in the engine. GUI visual representation does not sync with actual data right after save is loaded, only when forced to by some event.

I think the temporary workaround may be to "tweak" gui a little in on_event with eEventRestoreGame, for example change it position by 1 pixel and back immediately.

Yeah, I figured as much. As there is currently only one element that bugs out for me, I set up this in my GlobalScript to handle the issue:

Code: ags
function on_event (EventType event, int data)
{
  if(event == eEventRestoreGame) {
    UpdateNavMap();
    
    if (gSuitLevelScan == 1) {
      btnNavMapFaceplate.NormalGraphic = 162;
    } else if (gSuitLevelScan == 2) {
      btnNavMapFaceplate.NormalGraphic = 27;
    } else if (gSuitLevelScan == 3) {
      btnNavMapFaceplate.NormalGraphic = 28;
    } else {
      btnNavMapFaceplate.NormalGraphic = 29;
    }
  }
}
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

Crimson Wizard

I think you may do this:

Code: ags

function on_event (EventType event, int data)
{
  if(event == eEventRestoreGame) {
    for (int i = 0; i < Game.GUICount; i++) {
        for (int j = 0; j < gui[i].ControlCount; i++) {
            Button* btn = gui[i].Controls[j].AsButton;
            if (btn != null) {
                int graphic = btn.NormalGraphic;
                btn.NormalGraphic = 0;
                btn.NormalGraphic = graphic;
            }
        }
    }
  }
}



But I'm planning to fix this and release a new 3.5.0 patch.

WHAM

Much more elegant than my solution. My code was just copied as-is from the original code that sets the button graphic in question, so it was the quickest solution for me (and required zero brainpower to perform).
Also: yay! I feel useful for having reported an actual bug for once, rather than just doing something wrong myself!  (laugh)
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

Crimson Wizard

Here's a temp build for next patch: https://cirrus-ci.com/task/4901340306472960
you may choose download either installer or archive.

Please tell if this works for you, and if it suddenly causes more problems.

Vincent

Quote from: WHAM on Thu 25/02/2021 19:54:56
I use a button graphic to display some information, and just swap the buttons normalgraphic with code run when player changes rooms.
However, if the player saves the game, exits and loads the game, the button graphic defaults to the original default value given in the GUI settings for that button, rather than the state it should have been saved in.

Ah I thought I was the only one with this problem.

WHAM

Quote from: Crimson Wizard on Fri 26/02/2021 21:09:01
Here's a temp build for next patch: https://cirrus-ci.com/task/4901340306472960
you may choose download either installer or archive.

Please tell if this works for you, and if it suddenly causes more problems.

Yes, this seems to fix the issue for me, and on a quick test I didn't notice any major issues other than my antivirus (F-secure) giving a really ugly error when I tried to compile my game. It seems to recognize the editor as a ransomware application and blocks is, so I had to exclude the folder from being protected by F-secure to get around that issue. Not sure if that's relevant at all, but felt I should mention that just in case.
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

SMF spam blocked by CleanTalk