Values visually reset to original values after saving.
Giggitybyte opened this issue ยท 10 comments
Setting a value then saving it will cause all values to revert to their original state when the screen was first opened.
Closing then reopening the screen will read the updated value.
2022-12-19.20-34-19.mp4
MC 1.19.3
YACL 2.1.1
You have most likely implemented the binding wrong. YACL explicitly resets the pending value upon applying options. Could you send your binding code?
My full implementation is here.
Have you considered using YACL's config API rather than your own? It may fix your issues.
Wasn't aware of it, but I want to stick with what I made.
I don't understand how that'd affect anything anyways; the source of the config value should not cause issues like this.
When you click 'Apply Value', two things happen:
- The values stored in the options are passed to your binding setter
- The stored value in the options is set to the binding getter
The problem lies in step number 2. Your config doesn't seem to update instantly and the binding getter is still the old value.
My config does update instantly as you can see in my video above.
It is stored in memory as a JsonObject
(from gson) which is essentially just a hashmap; those values are updated as soon as YACL invokes my lambda. YACL also calls the method which saves my config and writes the updated values which were in memory.
The screen created by YACL simply resets to the original value that it had when it was first opened no matter how many times you change the value and reapply it.
I see the changes to my config in memory through my debugger, and I see the changes written to my JSON file. This problem is not on my end.
Frustrated over this issue I decided to debug this further and understand why the binding was always returning the old value when I clearly see it set the new value, and I couldn't for the life of me figure out where the hell it was getting that value from. On a whim, I decided to swap out the method reference that I've been providing for each binding getter with a lambda; it now works exactly as intended.
My question is: why? That was the only thing I changed in the whole setup. Why does this make a difference?