While scripting, I’ve noticed that there is a Daily Variable (_tonicDjinn) set up to track whether the player has used a Tonic Djinn that day. However, it always remains false, making it completely useless.
I searched through the source code, and I quickly found out why.
When a Tonic Djinn is used, the response text is parsed for certain strings:
There is a major problem with this: the string “put the bottle away” is present both when cancelling and when trying to use it a second time. This means that players who have already used one outside of KoLmafia will not have _tonicDjinn set to true, as the code acts like they could use it but cancelled. Because of the order of the checks, that means _tonicDjinn will always remain false.
I solved this in the attached SVN patch by swapping the order of the checks. In the revised code, the “already had a wish today” string is checked first. If present, it sets _tonicDjinn to true then finishes. This effectively updates the variable if a Tonic Djinn was used outside of KoLmafia. Next, it checks for the string “put the bottle away”. This definitely means the player cancelled, since they otherwise wouldn’t get that far in the function. If that is true, that returns without changing the variable. Finally, _tonicDjinn is set to true and breaks. That should only run if the player successfully used a Tonic Djinn.
If this isn’t the right place to submit SVN patches, please tell me where to do so. I spent quite a while looking for the right thread.
View attachment tonicFix.patch
I searched through the source code, and I quickly found out why.
When a Tonic Djinn is used, the response text is parsed for certain strings:
- “put the bottle away” is checked first, and finishes the function call. This is presumably meant to represent the player backing out of the use by choosing “Let me think about it.”.
- If the function continues, _tonicDjinn is set to true. This is supposed to mean that either the player used the Tonic Djinn or they were unable to.
- Finally, if the string “already had a wish today” is present, the function finishes.
There is a major problem with this: the string “put the bottle away” is present both when cancelling and when trying to use it a second time. This means that players who have already used one outside of KoLmafia will not have _tonicDjinn set to true, as the code acts like they could use it but cancelled. Because of the order of the checks, that means _tonicDjinn will always remain false.
I solved this in the attached SVN patch by swapping the order of the checks. In the revised code, the “already had a wish today” string is checked first. If present, it sets _tonicDjinn to true then finishes. This effectively updates the variable if a Tonic Djinn was used outside of KoLmafia. Next, it checks for the string “put the bottle away”. This definitely means the player cancelled, since they otherwise wouldn’t get that far in the function. If that is true, that returns without changing the variable. Finally, _tonicDjinn is set to true and breaks. That should only run if the player successfully used a Tonic Djinn.
If this isn’t the right place to submit SVN patches, please tell me where to do so. I spent quite a while looking for the right thread.
View attachment tonicFix.patch