PCTB crashes on Counterattack

I'm using "YSA Battle System: Predicted Charge Turn Battle" (I copied the version of the script in this topic). I also have other scripts; but the same issue happens when I copied this script alone into a new project.

When a party member is knocked out by an enemy's counterattack, this error comes up:

Script 'PCTB' line 815: NoMethodError occurred.

undefined method 'item' for nil:NilClass

(Nothing untoward happens when a party member takes damage from a counterattack without being knocked out, or when a party member is knocked out by a normal attack.)

Line 815 reads:

@subject.last_obj = @subject.current_action.item unless @subject.last_obj
95% of all cases, "Undefined for NIL" is caused by loading old savefiles.


In the case of complex scripts it's REQUIRED to start a new game to initialize data - all old saves become invalid the second you launch the game with the script included.


Did you start a new game?
Yes -- I started a brand-new project and made only the following changes:

* Imported the script in question

* Filled the starting map with walkable terrain, and set it to have the Slime x 2 random encounter

* Added "CNT 100%" to the Slime enemy and set its ATK to 999

and got the above crash the first time I fought a Slime and was killed by its counter.

I am sure I haven't made any changes to this script, but just in case, I deleted the script and re-imported it from the topic (rather than from my main project), and the crash still occurs.
This was kind of the same problem that I've had before when I used that script... First I thought it was because I was using Victor's counter script along with it but realized it was kinda in the script itself. I just forgot how I fixed it, sorry.

Original thread: https://forums.rpgmakerweb.com/threads/pctb-crashes-on-counterattack.45763/