[v1.7.0+] Negative Effect Timeout Cleanup

A place to post your add ons and ideas for them

Moderator: Moderator

Post Reply
Message
Author
Zizzo
Sher'Tul Godslayer
Posts: 2362
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

[v1.7.0+] Negative Effect Timeout Cleanup

#1 Post by Zizzo »

So it finally happened to me — a temporary effect that didn't expire when its duration fell below zero. (In my case it was triggered by another error, about which more elsewhere. :oops: ) At least now that I have a viable test case to work with, I can take a stab at fixing it, or at least cleaning up behind it. What I've got so far is my new (and rather clumsily named) Negative Effect Timeout Cleanup addon

So here's the basics of what's happening: The :setEffect() method sets a temporary "we're in the middle of setting up this effect" flag on an effect while it's in the process of adding it to an actor, and clears that flag when the effect is in place and ready to go. The :removeEffect() method checks for that flag and, if it's present, delays removing the effect until the flag is cleared. (I guess there was an issue with effects being removed out from under themselves?) Problem is, if a stack trace happens inside :setEffect(), that "setting-up" flag never gets cleared, and thus :removeEffect() will never remove the effect.

The fix I'm going with for this pass is in the related :timedEffects() method, which is called once per turn to decrease effect countdowns and handle their actual, well, effects. My theory is that it shouldn't be possible for us to be in the middle of setting up an effect at that point, so any "setting up this effect" flags we may find lying around at that point must be spurious and thus should be cleared.

And since this is exactly the sort of addon that people will likely want to add to a savefile retroactively, I'll go ahead and take a stab below at a FAQ on how to do so that I can link back to from the Steam page.

[And since this is pretty explicitly a bugfix addon, I'm hesitant to include it in ZOmnibus, since we'd have to claw it back out if the bug is fixed later.]

[Implementation notes:]

Code: Select all

Superload:
  mod.class.Actor:
    timedEffects() [to clear stuck __setting_up flags]
"Blessed are the yeeks, for they shall inherit Arda..."

Zizzo
Sher'Tul Godslayer
Posts: 2362
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: [v1.7.0+] Negative Effect Timeout Cleanup

#2 Post by Zizzo »

Frequently Asked Questions:

My character has a temporary effect that won't go away! Can I use this addon to fix it?

Well, if you're in this situation, you presumably didn't have this addon enabled when you created the character, which means you'll need to add it retroactively. Installing and enabling the addon after the character is created generally won't do that; you'll need to a bit of savefile surgery:
  • First, find where your ToME savefiles live:
    • On Linux, this is the directory $HOME/.t-engine/4.0/tome/save/.
    • On Windows, this is the directory %userprofile%\T-Engine\4.0\tome\save. [h/t Moasseman]
    • On Mac, in the Finder, select "Go to" ⇒ Library ⇒ Application Support ⇒ T-engine ⇒ 4.0 ⇒ tome ⇒ save. [h/t Lakeere]
  • In this directory, there should be a folder named for your character, and in that folder there should be a file named "desc.lua". Open that file with your favorite text editor.
  • The file will have a line of the form "addons = { … }", listing the ID tags for all addons that are enabled for this character. You'll want to add this addon's tag, "neg_eff_fix", to that line; the necessary syntax should be clear.
  • Save this change and re-run ToME. In the Load Game dialog, check that the "neg_eff_fix" tag you just added is present and green in your character's addons list (if it's red, either you misspelled the tag or you haven't actually installed the addon).
  • Load the game and wait a turn or take any action. The stuck effects should be cleared. (If they aren't, there must be another bug somewhere; this thread would be an excellent place to report that.)
Last edited by Zizzo on Fri Sep 22, 2023 7:04 pm, edited 1 time in total.
"Blessed are the yeeks, for they shall inherit Arda..."

visage
Archmage
Posts: 340
Joined: Fri Jan 10, 2014 4:09 pm

Re: [v1.7.0+] Negative Effect Timeout Cleanup

#3 Post by visage »

Zizzo wrote: Tue Jul 12, 2022 11:16 pm you'll need to add it retroactively. Installing and enabling the addon after the character is created generally won't do that; you'll need to a bit of savefile surgery:
I wish I'd known that procedure long ago! So many time's I've aborted a run after discovering or creating a QoL mod...

Zizzo
Sher'Tul Godslayer
Posts: 2362
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: [v1.7.0+] Negative Effect Timeout Cleanup

#4 Post by Zizzo »

visage wrote: Wed Jul 13, 2022 11:10 am I wish I'd known that procedure long ago! So many time's I've aborted a run after discovering or creating a QoL mod...
I should probably stress that not all addons can be added retroactively by this method. Anything that needs to set up any infrastructure when the character is created, for instance, will obviously not get that chance, and addons that affect certain zones will probably not have the desired effect if you've already visited the relevant zone. Quality-of-life or pure UI-modification addons, and especially addons like this one or Particle Cleanup that are designed with retroactive addition in mind, are more likely to work. (As a general rule of thumb, the more complex an addon is, the more likely it is to break messily if you try to add it this way.)
"Blessed are the yeeks, for they shall inherit Arda..."

Post Reply