Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Request] Unload Event

1367827246
Alex L.
Pro
Sheet Author
Basically an event that goes off just before the sandbox starts to be unloaded. Example: I have a script that changes the controlledby field on a character based on who's turn it is so only the person who's turn it is can move there token. Before the script is unloaded prior to a restart or being disabled i need to set the controlledby field of every character back to its original value.
Why not just move the token back to its previous spot instead?
1367831402
Alex L.
Pro
Sheet Author
Because I want to disable the tokens movement for the player and not the GM, also I don't need the player to be able to edit the token any other time as I have auto damage functions. Also its an example, there are many other things you may want to do like store the current state of the game, etc.
This is unfortunately not something we would be able to reliably provide. For example, if your script errors out, it immediately exits, there would be no way to run any further code. I think in your example a better way to go would be to use the state object (again, assuming it's going to save between sessions) to store something like "state[obj.id][original_controlledby]", and then on script *startup* you would look for any of those that were still remaining, and reset things back to a good "known" state. So basically your script should be able to tell that things were in a bad state when it exited and recover from that.
1367847274
Alex L.
Pro
Sheet Author
I meant more for when the script is reset due to saving or disabling not for when it crashes as no language that has something like onUnload events ever triggers them on crash and I wouldn't expect them to. But for now once state is working I will use that to check if everything is in its working state, or may use my storage class. Also my mane use isn't to make it usable for when the script restarts but to make it usable for the players/gm should they not load the script up again.