Script 'Window_Selectable' line 61: ZeroDivisionError Occurred - Divided by 0

Status
Not open for further replies.

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV
So, as the title says... That's my problem. I've obviously made a huge mistake somewhere if this thing's attempting to divide by 0 :aswt: This occurs when I attempt to enter a battle in a playtest run of the game. It doesn't happen when I battle test from the troops menu.

All of the original scripts for the engine are untouched.
My script list(This is in order):
YanFly Core Engine
YanFly Party System
YanFly Command Party
YanFly Battle Engine
YanFly Battle Engine Add-On Element Pop-Up
YanFly Battle Engine Add-On HP Bars
YanFly Battle Engine Add-On Victory Aftermath
YanFly Visual Battlers
Khas Ultra Lighting(All of it)
EatYourBeets jumping script
SirBilly's Turn&Move(allows me to turn in place without the character actually moving)
Celianna's Variable Pictures script(I heavily modified her time system with Khas's lighting)
Shaz's Mouse Script with its "Awesome Cool Fix"

-----------------------------------------------

I have no idea how I could have caused this, and I've tried everything. I really hate to be a bother and ask for help, but would anybody care to help me out and fix this, please?
 

Attachments

  • Screenshot_43.png
    Screenshot_43.png
    6.1 KB · Views: 10

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,750
Reaction score
8,744
First Language
English
Primarily Uses
RMMV

I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV

I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

My apologies, mlogan!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,306
Reaction score
1,330
First Language
Spanish
Primarily Uses
RMVXA
check definitions of col_max returning 0
make sure they return 1 or higher

Code:
def row_max
    [(item_max + col_max - 1) / col_max, 1].max
end
 
Last edited:

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV
check definitions of col_max returning 0
make sure they return 1 or higher

Code:
def row_max
    [(item_max + col_max - 1) / col_max, 1].max
end
That's exactly what mine is, and that's why it's so confusing. Original scripts are untouched, and this was never an issue until quite recently. All I had done was add new sprites to my list, and... Boom. Just out of the blue, I can't start battles anymore and this thing's dividing by zero, it's really strange.

The only thing I really know about programming and coding is modifying existing things, and only if it's something where it's really broken down(like at the top of YanFly's Visual Battlers, where it's to adjust their alignments on the screen.) so this is just something that I'm pretty much a doe in the headlights with, lol.
 

Attachments

  • Screenshot_45.png
    Screenshot_45.png
    14.6 KB · Views: 9

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,306
Reaction score
1,330
First Language
Spanish
Primarily Uses
RMVXA
that's what you *don't* have to fix *that* line.
that line is your starting point.
from there, backtrack and debug all the lines that lead up to it.

do a game-wide search for any other occurences of col_max.
one of them is returning 0

also, paste this code
Code:
def report_exception(error)
  scripts_name = load_data('Data/Scripts.rvdata2')
  scripts_name.collect! {|script|  script[1]  }
  backtrace = []
  error.backtrace.each_with_index {|line,i|
    if line =~ /{(.*)}(.*)/
      backtrace << (scripts_name[$1.to_i] + $2)
    elsif line.start_with?(':1:')
      break
    else
      backtrace << line
    end
  }
  error_line = backtrace.first
  backtrace[0] = ''
  err_class = " (#{error.class})"
  back_trace_txt = backtrace.join("\n\tfrom ")
  error_txt = sprintf("%s %s %s %s %s %s",error_line, ": ", error.message, err_class, back_trace_txt, "\n" )
  print error_txt
  return error_txt
end
begin
  rgss_main do
    begin
      loop do
        Input.update
        if Input.trigger?(Input::C)
          break
        end
      end
      SceneManager.run
    end
  end
rescue SystemExit
  exit
rescue Exception => error
  error_txt = report_exception(error)
  print "Submit the file \"ErrorLog.txt\" in your project folder to the upper most script creators noted in the message.\n"
 
  filename = "ErrorLog.txt"
 
  File.open(filename, 'w+') {|f| f.write(error_txt + "\n") }
  raise  error.class, error.message, [error.backtrace.first]
end
overwriting the Main function.
this will dump a stack trace to the console.
I don't know where I got this from, it's not mine.... but it helps.
 
Last edited:

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV
that's what you *don't* have to fix *that* line.
that line is your starting point.
from there, backtrack and debug all the lines that lead up to it.

do a game-wide search for any other occurences of col_max.
one of them is returning 0
...I think I found it. In the Window_Selectable
This?
Code:
  #--------------------------------------------------------------------------
  # * Get Number of Items
  #--------------------------------------------------------------------------
  def item_max
    return 0
  end

It says return 0, change that to 1?
(I'm sorry if my lack of knowledge here is annoying, truly.)

*Edit*
No, that's not it.

*One last edit*
I just saw your code post, I had mistaken that for your signature. I'll try it :)
 
Last edited:

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,891
Reaction score
642
First Language
English
Primarily Uses
RMVXA
I would say it's something to do with the sprites then. What is the list you used when adding the sprites?
Probably a typo in the names. Can't find the file, hence divide by 0 since no sprite found.
 

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV
I would say it's something to do with the sprites then. What is the list you used when adding the sprites?
Probably a typo in the names. Can't find the file, hence divide by 0 since no sprite found.
I fixed it, but am extremely ashamed of myself, and will shamefully explain what my simple mistake was in case someone ever stumbles across this thread. You're kind of right that it was a typo, except the typo was in my event :aswt:
I had, uh... Misclicked... And selected the wrong troop(an empty troop) for battle processing :aswt:
I had went to set some dialogue in the build up to that fight while waiting for someone to aid me on here in fixing the problem I was having, and noticed that the troop name wasn't what I had thought I selected, so I had switched it(because why not, you know? Eventually I'll figure out what's wrong, so it's best to set it up correctly so I don't skip over it and forget.) I was going to ignore the crash to test when exactly it would start processing the battle(because it pulls up the menu for you to change your party members right before.) and it just magically started a battle.
So, naturally, you would think "Okay, well, obviously there is something wrong with the troop I had selected. What is it?"
Went and checked in the troop section of the database... Empty. That's why I couldn't find what col_max was returning 0 in my scripts, because they weren't. I had ignorantly and stupidly put in an empty troop.

I'm so sorry, guys :|
*hangs head in shame*

Feel free to laugh, because it is pretty funny. So painful to admit this :guffaw:
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,306
Reaction score
1,330
First Language
Spanish
Primarily Uses
RMVXA
That's why I couldn't find what col_max was returning 0 in my scripts, because they weren't
Code:
def item_max
   $game_troop.alive_members.size
end

there's the problem then: no alive members since troop = none.
that code is from window_battleenemy, which inherits from window_selectable.
it found a problem, backtracked to it's parent function, and the parent function called up the error

but it still returns *divided by zero*, not, *zero divided by x*, which is weird
here,
Code:
[(item_max + col_max - 1) / col_max, 1].max

that .max at the end should have handled the error..... :/
as in, [(0 + 1 - 1 / 1), 1].max, out of (0) and 1, pick the highest, which is 1.


anyways, use that code I posted, and keep the console always up.
when there's an error, it'll put up the follow up to that error, so if you find an instruction that appears to be fine, check the next one on the list.
 
Last edited:

PhoenixX92

The Light Bearer
Veteran
Joined
Jun 28, 2015
Messages
219
Reaction score
95
First Language
English
Primarily Uses
RMMV
Code:
def item_max
   $game_troop.alive_members.size
end

there's the problem then: no alive members since troop = none.
that code is from window_battleenemy, which inherits from window_selectable.
it found a problem, backtracked to it's parent function, and the parent function called up the error

but it still returns *divided by zero*, not, *zero divided by x*, which is weird
here,
Code:
[(item_max + col_max - 1) / col_max, 1].max

that .max at the end should have handled the error..... :/
as in, [(0 + 1 - 1 / 1), 1].max, out of (0) and 1, pick the highest, which is 1.


anyways, use that code I posted, and keep the console always up.
when there's an error, it'll put up the follow up to that error, so if you find an instruction that appears to be fine, check the next one on the list.
Yeah, I'm using that script you posted. I appreciate it, thank you. It will be a huge help when I finally play my project in its entirety and try every way possible to break it.

Regarding the troops, I had apparently removed the 'slimes' from the troop list, and it was just an empty troop. Once I had swapped it to another troop that had some enemies in it, the battle worked. Closed, added some enemies to the "slime" troops, it also worked.

I really appreciate all of your help, @gstv87.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,181
Reaction score
836
First Language
Hungarian
Primarily Uses
RMVXA
but it still returns *divided by zero*, not, *zero divided by x*, which is weird
here,
Code:
[(item_max + col_max - 1) / col_max, 1].max

that .max at the end should have handled the error..... :/
as in, [(0 + 1 - 1 / 1), 1].max, out of (0) and 1, pick the highest, which is 1.
If there are no alive members (and an empty troop doesn't have any members, let alone alive ones :D), than it will try to divide by 0, because col_max will be 0.
This is only true if Yanfly's Battle Engine is used in the project, so I guess, it is used.
But 0 can be divided by any numbers, that kind of error doesn't exist, so it would be even more weird to get an error like that. :p
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,306
Reaction score
1,330
First Language
Spanish
Primarily Uses
RMVXA
If there are no alive members (and an empty troop doesn't have any members, let alone alive ones :D), than it will try to divide by 0, because col_max will be 0.
This is only true if Yanfly's Battle Engine is used in the project, so I guess, it is used.

no, troop members only modify item_max, not col_max
col_max is a window property, not a troop property.
the window arranges itself in X columns, and if there are more battlers than columns, it adds a row.
if the number of battlers is 0, the window would still be expecting to load up col_max as many columns, only, empty.

if Yanfly modified that the wrong way, well.... ¯\_ツ_/¯
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,181
Reaction score
836
First Language
Hungarian
Primarily Uses
RMVXA
Code:
def col_max; return item_max; end
From Yanfly's Battle Engine.
But to be fair, there would be no point entering any battle without any enemies, so it's just a missed fail-proof check which isn't really necessary.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,306
Reaction score
1,330
First Language
Spanish
Primarily Uses
RMVXA

EVXA

Villager
Member
Joined
Aug 20, 2020
Messages
26
Reaction score
0
First Language
English
Primarily Uses
RMVXA
This is so helpful, I modified the line to def col_max; return item_max+1; end in yanfly's battle system, this stopped my issue for now I was running into this issue during a battle end scenario due to how I was running battle in real time.

Edit, thx Sixth, I thought about doing something like that but I don't code, I'll definitely give that a try,
 
Last edited:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,181
Reaction score
836
First Language
Hungarian
Primarily Uses
RMVXA
@EVXA
You should do this instead:
Code:
def col_max; return [item_max,1].max; end
This will only correct the column number if it's needed, instead of always adding 1 to it.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,149
Reaction score
14,206
First Language
English
Primarily Uses
RMMV

EVXA, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Does anyone know of NPC sprites for RMMZ? I know of Flirion's RMMV recolours, but RMMZ's sprites are slimmer and more detailed, so I'm a bit on the edge to use Flirion's im RMMZ...
I can't believe that after all those years, KH Union X Dark Road is closing the services.

Due to a situation in which I thought plugin adaptations had stopped for the QPlugins, I "ghetto" converted these 7 over yesterday. They appear to work perfectly as long as you use old style plugin commands. I am uncertain if I will have a lot of free time in the future to work on this, but if you'd like them, here they are.
Was there a thread that you could share a screenshot of your game? I feel like I found it once but can't locate it again.

I was being lazy and just copied a map to test a new parallax, but I forgot to delete all the events. This was the result. :o

Forum statistics

Threads
108,818
Messages
1,039,786
Members
141,277
Latest member
acoolusername
Top