feat: Add on_script_reloaded callback. #421
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I added an
on_script_reloaded
function that is called before and after on_script_loaded on reloads. This addresses the issue I filed #419.I updated the core-callbacks doc with example code. Here's the example code shown there:
I'm not certain about the name.
on_script_reload
might be the name I'd choose with a blank slate.Alternatives
One could designate a special variable to capture. But I think a function is preferable because a reload can interrupt at any time and keeping that value up to date all the time instead of when it's required seems inefficient.
One could break this into two functions, but they don't do anything unless both are implemented so it seemed wise to keep them as a single function.
Testing
I exercised it manually with errors in both the saving of state and restoring state, and both were reported as the usual mechanism.
Mistake
I started this branch on top of my other pull request #418. Oops. Luckily #418 is not controversial or large.