script 'window_base' line 362: floatdomainerror occurred. nan

So yeah um out of nowhere sometimes at random I get this error pop up which crashes the game

Script 'Window_Base' line 362: FloatDomainError occurred. nan

the line in script reads:     fill_w = (width * rate).to_i

This makes zero sense to me because this happens at random, i can move the player around several rooms and it chooses to crash at anytime it pleases at any duration.
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


Window_Base line 362 is in the draw_gauge method.


What scripts have you added that draw a gauge or hud or something on the map? Provide links.
I think the most relevant script would be this: http://himeworks.com/2012/12/large-choices-built-in-multiple-choices/

My other scripts that may effect windows considering they use them in scripts and common events: https://github.com/Archeia/YEARepo/blob/master/Menu/Ace_Menu_Engine.rb

Oh and I also imported this script for a Stamina gauge though I altered the script to have the gauge itself to not display but still go into effect https://github.com/suppayami/rmvxa-collection/blob/master/Dash%20Stamina.rb

that one MIGHT be the issue but I cannot be sure.
It's not windows though. You said it happens while you're on the map, when there are no windows being displayed. Hime's Choice script doesn't uses gauges as far as I know, and the second script is for menus.


Do a global search in your scripts (control+shift+f) for draw_gauge and see which custom scripts show up in the results list.
Well it tends to happen when no windows are open yes. Also given the searches I realized I also have the Ace_Battle_System script by the Yanfly Channel Engine Ace

The list i got from doing the script searches are:

Window_Base line 361    def draw_gauge(x, y, width, rate, color1, color2)

Window_Base line 497    draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)

Window_Base line 507    draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)

Window_Base line 517    draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)

Ace_Battle_Sytem line 1905    draw_gauge(dx, dy, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)

Ace_Battle_Sytem line 1917    draw_gauge(dx, dy, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)

Ace_Battle_Sytem line 1929    draw_gauge(dx, dy, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)

Stamina Script line 310    draw_gauge(x, y, width,$game_player.stamina_rate, stamina_bar_color1, stamina_bar_color2)
I bet it's the stamina script - especially if you've modified it. What were your changes?


Disable that script and see if the problem still happens. Even though it's random, if you normally have the issue within a minute or so of playing, you'll soon know whether it's still happening or not.
Most probably yes, when I searched for a stamina script I came across a few but this one I chose was the most compressed and was easy to modify but it seems to leave me crashes, do you know of a script that can be easily fixed to have no window show at all?
It's probably giving a stamina value rate of undefined or NaN (Not a Number)... We need to find out why it would be doing so.


Are you playing a new game, or using an already saved file made before you added the script? If you're loading a saved game, please try playing a new one.
What were your changes?
Did you disable the script and play without crashes?


No need to search for a new one - we just need to see what you did to disable it (and answer the question above about saved game vs new game) and we can probably fix it fairly easily.


Another option is to replace your modified version with the original and play for a while to see if it still crashes, and then to make the correct change to disable the bar.
I've started new games several times and it seems to occur then,

Here's the modified script of the stamina gauge:

Spoiler
#==============================================================================
#
# ▼ Yami Engine Symphony - Dash Stamina
# -- Last Updated: 2013.02.27
# -- Level: Easy
# -- Requires: n/a
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YES-DashStamina"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2013.02.27 - Added recover method.
# - Added rest area feature.
# 2012.11.18 - Fixed Enable Window option.
# 2012.11.17 - Added recovery frames.
# - Added stamina variable.
# - Fixed recovery problem when holding Shift.
# 2012.11.15 - Started and Finished Script.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides stamina feature for dashing on map. Dashing will comsume
# stamina and be disable if run our of stamina.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Script Calls - These commands are used with script calls.
# -----------------------------------------------------------------------------
# YES.recover_stamina
# Fully recover stamina for player.
#
# YES.recover_stamina(X)
# Recover X stamina for player.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjustments.
#
#==============================================================================

#==============================================================================
# ■ Configuration
#==============================================================================

module YES
module DASH

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - General Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
STAMINA_DEFAULT = 100 # Default Stamina for player.
STAMINA_PER_FRAME = 1 # Default Stamina cost per frame while dashing.
MOVE_RESTORE = false # Set this to false to disable restoring
# stamina while moving.
RECOVER_FRAMES = 120 # Start recovering after X frames.
STAMINA_RESTORE = 5 # Restoring Stamina per X frames.
RESTORE_AFTER = 10 # Restore Stamina after X frames.
REST_AREA_RATE = 1 # Restore rate when standing on rest area.
# Set this to 1 to disable rest area function.
REST_AREA_REGION = 19 # Region ID of rest area.

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Switches and Variables Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
STAMINA_VARIABLE = 10 # Variable to control stamina.
DISABLE_SWITCH = 98 # Switch to toggle Stamina Feature.
# Set to true to disable Stamina Feature.

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Windows Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ENABLE_WINDOW = false # Toggle stamina window.
AUTO_HIDE_WINDOW = true # Toggle auto-hide function for Stamina Window.
HIDE_AFTER_FRAMES = 0 # Hide after X frames if not dashing.
STAMINA_TEXT = "Stamina"
WINDOW_WIDTH = 0
BAR_COLORS = { # Settings for stamina bar colors.
:color1 => 28,
:color2 => 29,
} # Do not remove this.

end # DASH
end # YES

#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

#==============================================================================
# ■ Module Yami Engine Symphony
#==============================================================================

module YES

#--------------------------------------------------------------------------
# self.recover_stamina
#--------------------------------------------------------------------------
def self.recover_stamina(amount = :full)
$game_player.recover_stamina(amount)
end

end # YES

#==============================================================================
# ■ Game_Player
#==============================================================================

class Game_Player < Game_Character

#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :stamina_backup

#--------------------------------------------------------------------------
# alias method: initialize
#--------------------------------------------------------------------------
alias dash_initialize initialize
def initialize
dash_initialize
#---
@stamina = YES:😀ASH::STAMINA_DEFAULT
$game_variables[YES:😀ASH::STAMINA_VARIABLE] = YES:😀ASH::STAMINA_DEFAULT
#---
@recover_frames = 0
@stamina_backup = {}
end

#--------------------------------------------------------------------------
# new method: stamina
#--------------------------------------------------------------------------
def stamina
return @stamina
end

#--------------------------------------------------------------------------
# new method: stamina_max
#--------------------------------------------------------------------------
def stamina_max
$game_variables[YES:😀ASH::STAMINA_VARIABLE]
end

#--------------------------------------------------------------------------
# new method: stamina_rate
#--------------------------------------------------------------------------
def stamina_rate
stamina.to_f / stamina_max.to_f
end

#--------------------------------------------------------------------------
# new method: stamina_cost
#--------------------------------------------------------------------------
def stamina_cost
[YES:😀ASH::STAMINA_PER_FRAME, @stamina].min
end

#--------------------------------------------------------------------------
# new method: recover_stamina
#--------------------------------------------------------------------------
def recover_stamina(amount = :full)
if amount.is_a?(Integer)
@stamina += amount
correct_stamina
else
@stamina = stamina_max
end
end

#--------------------------------------------------------------------------
# alias method: update
#--------------------------------------------------------------------------
alias dash_update update
def update
dash_update
update_dash_stamina
#---
correct_stamina
#---
update_stamina_recover
end

#--------------------------------------------------------------------------
# new method: correct_stamina
#--------------------------------------------------------------------------
def correct_stamina
@stamina = stamina_max if @stamina > stamina_max
@stamina = 0 if @stamina < 0
end

#--------------------------------------------------------------------------
# new method: update_dash_stamina
#--------------------------------------------------------------------------
def update_dash_stamina
return unless moving?
return unless dash?
@stamina = @stamina - stamina_cost
@stamina = 0 if @stamina < 0
@recover_frames = YES:😀ASH::RECOVER_FRAMES
end

#--------------------------------------------------------------------------
# new method: update_stamina_recover
#--------------------------------------------------------------------------
def update_stamina_recover
@recover_frames -= 1
return if @recover_frames > 0
return if moving? && YES:😀ASH::MOVE_RESTORE
return unless Graphics.frame_count % YES:😀ASH::RESTORE_AFTER == 0
return correct_stamina if @stamina >= stamina_max
@stamina += stamina_recover
@stamina = stamina_max if @stamina > stamina_max
end

#--------------------------------------------------------------------------
# alias method: dash?
#--------------------------------------------------------------------------
alias stamina_dash? dash?
def dash?
return false if @stamina <= 0 && !$game_switches[YES:😀ASH:😀ISABLE_SWITCH]
return stamina_dash?
end

#--------------------------------------------------------------------------
# new method: stamina_recover
#--------------------------------------------------------------------------
def stamina_recover
YES:😀ASH::STAMINA_RESTORE * rest_area_rate
end

#--------------------------------------------------------------------------
# new method: on_rest_area?
#--------------------------------------------------------------------------
def on_rest_area?
region_id == YES:😀ASH::REST_AREA_REGION
end

#--------------------------------------------------------------------------
# new method: rest_area_rate
#--------------------------------------------------------------------------
def rest_area_rate
on_rest_area? ? YES:😀ASH::REST_AREA_RATE : 1
end

end # Game_Player

#==============================================================================
# ■ Window_Stamina
#==============================================================================

class Window_Stamina < Window_Base

#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
super(24, Graphics.height - 74, YES:😀ASH::WINDOW_WIDTH, 50)
@time = YES:😀ASH::HIDE_AFTER_FRAMES
refresh
#---
$game_player.stamina_backup[:x] ||= self.x
$game_player.stamina_backup[:time] ||= @time
self.x = $game_player.stamina_backup[:x]
@time = $game_player.stamina_backup[:time]
end

#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
return if @stamina && @stamina == $game_player.stamina
contents.clear
#---
draw_stamina_bar(0, 0, YES:😀ASH::WINDOW_WIDTH - 24)
#---
@stamina = $game_player.stamina
end

#--------------------------------------------------------------------------
# stamina_bar_color1
#--------------------------------------------------------------------------
def stamina_bar_color1
text_color(YES:😀ASH::BAR_COLORS[:color1])
end

#--------------------------------------------------------------------------
# stamina_bar_color2
#--------------------------------------------------------------------------
def stamina_bar_color2
text_color(YES:😀ASH::BAR_COLORS[:color2])
end

#--------------------------------------------------------------------------
# draw_stamina_bar
#--------------------------------------------------------------------------
def draw_stamina_bar(x, y, width = 156)
draw_gauge(x, y, width,$game_player.stamina_rate, stamina_bar_color1, stamina_bar_color2)
change_color(system_color)
draw_text(x, y, contents.width, line_height, YES:😀ASH::STAMINA_TEXT)
draw_current_and_max_values(x, y, width, $game_player.stamina,
$game_player.stamina_max, normal_color, normal_color)
end

#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def update
super
update_hide
update_show
update_input
refresh
$game_switches[YES:😀ASH:😀ISABLE_SWITCH] ? self.hide : self.show
self.hide unless YES:😀ASH::ENABLE_WINDOW
end

#--------------------------------------------------------------------------
# update_hide
#--------------------------------------------------------------------------
def update_hide
return unless YES:😀ASH::AUTO_HIDE_WINDOW
return if $game_player.dash?
@time -= 1
return unless @time <= 0
#---
self.x -= 9 if self.x > -self.width
end

#--------------------------------------------------------------------------
# update_show
#--------------------------------------------------------------------------
def update_show
return unless YES:😀ASH::AUTO_HIDE_WINDOW
return unless @show
@time = 180
self.x += 8 if self.x < 24
@show = false if self.x >= 24
end

#--------------------------------------------------------------------------
# update_input
#--------------------------------------------------------------------------
def update_input
return unless $game_player.dash?
return unless $game_player.moving?
@show = true
end

#--------------------------------------------------------------------------
# dispose
#--------------------------------------------------------------------------
def dispose
$game_player.stamina_backup[:x] = self.x
$game_player.stamina_backup[:time] = @time
super
end

end # Window_Stamina

#==============================================================================
# ■ Scene_Map
#==============================================================================

class Scene_Map < Scene_Base

#--------------------------------------------------------------------------
# alias method: create_all_windows
#--------------------------------------------------------------------------
alias dash_create_all_windows create_all_windows
def create_all_windows
dash_create_all_windows
create_dash_window
end

#--------------------------------------------------------------------------
# new method: create_dash_window
#--------------------------------------------------------------------------
def create_dash_window
@stamina_window = Window_Stamina.new
end

end # Scene_Map

#==============================================================================
#
# ▼ End of File
#
#==============================================================================
And your changes were? Sorry - I'm not going to go line by line through both scripts to look for differences.


Did you disable the script and see if the problem still happens?


Did you replace your modified version with the original and see if the problem still happens?


I have now asked the first question three times, and the second question twice. If you're not going to try what we suggest and tell us the results, you're making it really difficult for us to help you.
Apologies, I disabled the script and after playing around in the test for a while I didn't encounter any problems, it is hard to know exactly what is responsible because the crash seemed completely random-I believe the Stamina script changes I made were the problem, hopefully the list below shows you the only changes I made and make it easier for you to see into it.

First changes from the script was: line 63 STAMINA_DEFAULT = 100 # Default Stamina for player. from original script line STAMINA_DEFAULT = 200 # Default Stamina for player.

My intention here was to reduce the duration of the sprint

Second change from the script was: line 84 ENABLE_WINDOW = false # Toggle stamina window. from the original script line

ENABLE_WINDOW = true # Toggle stamina window.

This seems to hide the window display of the stamina bar, while the script is still in effect.

Third change from the script was: line 86 HIDE_AFTER_FRAMES = 0 # Hide after X frames if not dashing. from the original script line HIDE_AFTER_FRAMES = 300 # Hide after X frames if not dashing.
I turned this into 0 to stop the window from showing itself briefly when pressing for the menu, this also appears to be the script line that had the window move off the screen after a few seconds.

The last script line change is: line 88 WINDOW_WIDTH = 0 from the original script line WINDOW_WIDTH = 180

this I believe helped prevented the window display to to show much like above script change.
It MAY be the last line.


What if you just try commenting out the line create_dash_window under Scene_Map (near the bottom - in the original script) so it just doesn't create the window? If it doesn't create it, it won't try to update or refresh it. I'm not sure if any of the actual stamina processing is done in that window - if it's purely for display purposes it should still have the effect without the visual.
Looks like that saved me alot of trouble there, thanks for helping me with that. Since that might have been the cause for the gauge crashing the problem might be gone entirely. For some reason if it pops up again you have no problem bringing it to your attention once more?
no probs.
Have not run into any further errors, if I happen to I will PM. Thanks again!

Original thread: https://forums.rpgmakerweb.com/threads/script-window_base-line-362-floatdomainerror-occurred-nan.43955/