Casper CSCA Encyclopedia Crash

I've been having a crash related to Casper's CSCA Encyclopedia, when I kill a certain enemy. Here's the backtracer log.

Code:
Casper - CSCA Encyclopedia:1475:in `csca_set_defeated': undefined method `+' for nil:NilClass, NoMethodError
    from Casper - CSCA Encyclopedia:1758:in `perform_collapse_effect'
    from Yanfly - Ace Battle Engine:3030:in `perform_collapse_check'
    from Yanfly - Ace Battle Engine:3008:in `apply_item_effects'
    from MA - DW Individual Strikes:63:in `apply_item_effects'
    from Scene_Battle:597:in `invoke_item'
    from Yanfly - Ace Battle Engine:3109:in `invoke_item'
    from Yanfly - Ace Battle Engine:3093:in `block (2 levels) in use_item'
    from Yanfly - Ace Battle Engine:3093:in `times'
    from Yanfly - Ace Battle Engine:3093:in `block in use_item'
    from Yanfly - Ace Battle Engine:3089:in `each'
    from Yanfly - Ace Battle Engine:3089:in `use_item'
    from Yanfly - Ace Battle Engine:2990:in `execute_action'
    from Yanfly - Instant Cast:303:in `execute_action'
    from Yanfly - Visual Battlers:655:in `execute_action'
    from Scene_Battle:550:in `process_action'
    from Scene_Battle:48:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:23:in `run'
    from Main:10:in `block in <main>'

The enemy is no different from all the other enemies I have made, so I'm not really sure why it would crash, which leads me to believe there might be a weird script interaction or something. Here's line 1475 from the script.
Code:
  def csca_set_defeated(enemy, number = 1)
    @csca_defeated_number[enemy.id] += number
  end
That means whatever the enemy id is, there isn't a corresponding element in the @csca_defeated_number array.

Did you start and save a game, then add this script, then resume the saved game? That would cause this error.

If not, can you please provide a link to that script?
Or try this
Code:
((@csca_defeated_number ||= {})[enemy.id] ||= 0)+= number
That means whatever the enemy id is, there isn't a corresponding element in the @csca_defeated_number array.

Did you start and save a game, then add this script, then resume the saved game? That would cause this error.

If not, can you please provide a link to that script?
I honestly don't remember if I did the whole save, then add, then resume thing. One thing I could do is start a new game, and kill the enemy to see if it still crashes.

Script Link
Or try this
Code:
((@csca_defeated_number ||= {})[enemy.id] ||= 0)+= number

Well, I was about to say the same thing ... just in 10 lines 😀


I honestly don't remember if I did the whole save, then add, then resume thing. One thing I could do is start a new game, and kill the enemy to see if it still crashes.

Code:
    for i in 0..$data_enemies.size
      @csca_enemies[i] = false
      @csca_defeated_number[i] = 0
    end

Yes, this definitely sets up an element for each enemy when you start a new game, so would definitely cause that error if you resumed a game that you'd started & saved before adding the script.
Well, I was about to say the same thing ... just in 10 lines 😀
Eh now that I looked it back, I'm not even sure if this syntax would work.
More lines are probably better, for both making sure it works and readability.
I started a new game and the crash is gone. Problem solved! Looks like the save was the issue. Hopefully I won't have any other problems with it.
Just be aware that this happens sometimes with scripts - if you get any kind of "undefined" error, always try to recall if you added a script then resumed a game that had been started & saved earlier.
Looks like the save was the issue.
part of your current script data is always saved, and if you change scripts then load the old version of the script data, this can happen.
which means that as long as you're still changing scripts you have to start a new game at every playtest.

which is why we suggest to get the scripts done first, before doing any playtesting or story development.
for i in 0..$data_enemies.size

That's real nonsense! There's no enemy 0 (replace it with 1) nor enemy size like in 100 because the array actually has 101 elements. You'd need to add a third dot there to prevent any issues that might show up later on.

Original thread: https://forums.rpgmakerweb.com/threads/casper-csca-encyclopedia-crash.117075/