Pet Battle Scripts

Pet Battle Scripts

265k Downloads

Error when using Auto battle with default keybind

eafurness opened this issue ยท 3 comments

commented

I'm not sure if this is from the addon or the script being used. The error pops up when the 2nd pet comes in and tries to execute an action.

The script I'm using is from here: https://pastebin.com/3ywz5n4w

6x tdBattlePetScript/Core/Condition.lua:37: attempt to compare nil with number
[string "@tdBattlePetScript/Core/Condition.lua"]:37: in function <tdBattlePetScript/Core/Condition.lua:37>
[string "=(tail call)"]: ?
[string "=(tail call)"]: ?
[string "@tdBattlePetScript/Core/Condition.lua"]:97: in function Run' [string "@tdBattlePetScript/Core/Director.lua"]:53: in function Action'
[string "@tdBattlePetScript/Core/Director.lua"]:53: in function Action' [string "@tdBattlePetScript/Core/Director.lua"]:24: in function Run'
[string "@tdBattlePetScript/UI/PetBattle.lua"]:340: in function `OnAutoButtonClick'
[string "@tdBattlePetScript/UI/PetBattle.lua"]:86: in function <tdBattlePetScript/UI/PetBattle.lua:85>

Locals:
a = nil
b = 3
(*temporary) = nil
(*temporary) = "attempt to compare nil with number"

commented

Oh god, what is that?! I'm impressed it even runs at all.

I sadly can't reproduce the error. Then again, I'm also just stuck in a heal-pass-heal-pass-loop. Please give me a Rematch team and preferably also an enemy pet which reproduces the issue.

commented

Yeah, it's quite a large script written by another person. Before tdbattlescript was deprecated it was working properly from the forum posts on it. It's purpose was for sustained pet battles in the world so you can collect rare versions while also leveling pets. It even allowed for ending a battle if the leveling pet died in the first rounds.
Here's the post from Warcraft Pets detailing it in it's entirety: https://www.warcraftpets.com/community/forum/viewtopic.php?f=3&t=18464

Exported Rematch Team: Terrace's World Battlers (2)::ZL:11201J2:12103M:
I first noticed this battling Widow Spiderlings along the Western and NE edges of Twilight Grove in Duskwood.

Steps to reproduce:

  1. Enter the pet battle with team pre loaded - No faults
  2. Depress "A" hotkey for AutoBattle to initiate leveling pets first action. *Usually seems to be pass to allow one hit so pet gets xp. - No faults
  3. Opponent takes action, causes damage to leveling pet. - No faults
  4. Depress "A" hotkey for AutoBattle. Slot 1 (leveling pet) switches with Slot 2 (Pet with excellent self heal/dps capabilities). - No faults
  5. Depress "A" hotkey for AutoBattle to initiate Slot 2's attack. - Operation fails. Error code above is triggered.
  6. After the fault occurs, depressing the "A" hotkey only results in seeing the button depress/release. No actions occur.

Current Sessions error:

1x tdBattlePetScript/Core/Condition.lua:37: attempt to compare nil with number
[string "@tdBattlePetScript/Core/Condition.lua"]:37: in function <tdBattlePetScript/Core/Condition.lua:37>
[string "=(tail call)"]: ?
[string "=(tail call)"]: ?
[string "@tdBattlePetScript/Core/Condition.lua"]:97: in function Run' [string "@tdBattlePetScript/Core/Director.lua"]:53: in function Action'
[string "@tdBattlePetScript/Core/Director.lua"]:53: in function Action' [string "@tdBattlePetScript/Core/Director.lua"]:24: in function Run'
[string "@tdBattlePetScript/UI/PetBattle.lua"]:340: in function `OnAutoButtonClick'
[string "@tdBattlePetScript/UI/PetBattle.lua"]:86: in function <tdBattlePetScript/UI/PetBattle.lua:85>

Locals:
a = nil
b = 3
(*temporary) = nil
(*temporary) = "attempt to compare nil with number"

commented

The line in the script breaking is

use(Sunlight:404) [!weather(Sunny Day:403)&enemy(#1).quality<=3&enemy(#2).quality<=3&enemy(#3).quality<=3&enemy(#1).hp>250&enemy(#2).exists&enemy(#3).exists]

and the reason it breaks is

image

There is no enemy(#3). There is a guard for existence at the end of the line, but that's after the condition on it was evaluated. Changing the line to

use(Sunlight:404) [!weather(Sunny Day:403)&enemy(#1).quality<=3&enemy(#2).exists&enemy(#3).exists&enemy(#2).quality<=3&enemy(#3).quality<=3&enemy(#1).hp>250]

fixes the issue. Alternatively, only doing combat where there are two backline pets.

We had discussion on how nonexistent pets should handle in DengSir/tdBattlePetScript#26. The choice for quality there was "let it error out" since there is no sensible "default" quality. Scripts that would check it would need to have a enemy.exists guard to explicitly state intent of what happens if the enemy is missing.

You're in luck, in the end: There are only three lines checking for non-active-enemy quality in that script. You can simply change lines 202ff to

use(Sunlight:404) [!weather(Sunny Day:403)&enemy(#1).exists&enemy(#1).quality<=3&enemy(#2).exists&enemy(#2).quality<=3&enemy(#3).exists&enemy(#3).quality<=3&enemy(#1).hp>250]
use(Sunlight:404) [!weather(Sunny Day:403)&enemy(#2).exists&enemy(#2).quality<=3&enemy(#3).exists&enemy(#3).quality<=3&enemy(#2).hp>250]
use(Sunlight:404) [!weather(Sunny Day:403)&enemy(#3).exists&enemy(#3).quality<=3&enemy(#3).hp>250]

i.e. always having enemy(x).exists & enemy(x).quality, or enemy.quality only.

I would like to close this as won't-fix. Changing this to be a nice error instead would probably be issue #35. Impossible conditions should also be detected there, I think. Doing that change is a bigger one though, which you don't actually need, you just need the script fixed.