Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Save My Script!!!

I was making a script for a new game I'm working on, but I keep getting an error message saying something like: 'argument error line 27 (4 for 0)'

That is the line under def initialize that says 'super(0,0,620,300)'

Of course, I looked it over and I cannot find an error there, which leads me to believe that it's somewhere else in the script.  I looked through the entire script, but I just could not find it.  So, I'm posting the script here in hopes that someone will be willing to help me find the error.  I went through the entire script and commented everything to make it easier for whoever decides to help me (if anyone has the time).  I would greatly appreciate any help you can offer.  Thanks!

Here's the code:
Code:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Class Description Window by AbyssalLord
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#===============================================================================
#**Window_Class
#-------------------------------------------------------------------------------
#This displays descriptions of classes based on a variable.
#===============================================================================

class Window_Class

#-------------------------------------------------------------------------------
#Constant Variables
#-------------------------------------------------------------------------------
#CLASS_VAR - Variable ID that is used to determine which description is displayed.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# 0    :Invisible
# 1    :Mage
# 2    :Rogue
# 3    :Warrior
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

CLASS_VAR = 6

#-------------------------------------------------------------------------------
#Object Initialize
#-------------------------------------------------------------------------------
  
  def initialize
    super(0, 0, 620, 300)
    self.contents = Bitmap.new(width - 32,height - 32)
    @options = $game_variables[CLASS_VAR]
    refresh
  end
  
#-------------------------------------------------------------------------------
#Refresh
#-------------------------------------------------------------------------------

  def refresh
    #Clear contents
    self.contents.clear
    reset
   #return if variables does no equal 0..3
    return if options != 0..3
    case @options
    when 0 #draw nothing
      self.visible = false
    when 1 #mage
      self.contents.draw_text(0,0, 150, 50, "Mage", 2)
    when 2 #rogue
      self.contents.draw_text(0,0, 150, 50, "Rogue", 2)
    when 3 #warrior
      self.contents.draw_text(0,0, 150, 50, "Warrior", 2)
    end
  end
  
#-------------------------------------------------------------------------------
#Reset
#-------------------------------------------------------------------------------

  def reset
    @options = $game_variables[CLASS_VAR]
  end

#-------------------------------------------------------------------------------
#Frame Update
#-------------------------------------------------------------------------------

  def update
    super
    refresh if ( @options != $game_variables[CLASS_VAR] )
  end
end

#===============================================================================
#**Scene_Map
#-------------------------------------------------------------------------------
#  This class performs map screen processing.
#===============================================================================

class Scene_Map

#-------------------------------------------------------------------------------
#Alias Methods
#-------------------------------------------------------------------------------
  
  alias d_main main
  alias d_update update
  
#-------------------------------------------------------------------------------
#Main Processing
#-------------------------------------------------------------------------------
  
  def main
    @d = Window_Class.new
    d_main
    @d.dispose
  end
  
#-------------------------------------------------------------------------------
#Frame Update
#-------------------------------------------------------------------------------
  
  def update
   @d.update
   d_update
  end
end

Thanks again!
 

khmp

Sponsor

Window_Class must inherit from Window yes? That's the only thing causing your problem as well.
Code:
class Window_Class < Window_Base

Good luck with it AbyssalLord! :thumb:
 
You know...I've made a load of HUDs...it's pretty sad that I didn't notice that.  Thanks.

(I really need some more sleep)

EDIT: ok, now it's not giving me errors, but it is not updating, and it's not drawing text.
 

khmp

Sponsor

Scratch what I said I missed the point of why you would have an instance variable. My apology. Ok the error is caused by the testing of an uninitialized local variable just add that @ in front of it. Also your comparison is off. I just found this out myself and makes me feel a little dumb for suggesting the array thing :) Triple equals operator for a range checks to see if the element is inside the range.
Code:
return unless 0..3 === @options

Also you might want to say turn the visibility flag on when $game_variables is not zero. Right now if the variable is changed on map you won't see anything because the flag is still set to invisible. If you go to the menu and back to the map you will see it because it missed the toggle to invisible. Try this for your case statement:
Code:
    case @options
    when 0 #draw nothing
      self.visible = false
      return # Because we don't want it to become visible.
    when 1 #mage
      self.contents.draw_text(0,0, 150, 50, "Mage", 2)
    when 2 #rogue
      self.contents.draw_text(0,0, 150, 50, "Rogue", 2)
    when 3 #warrior
      self.contents.draw_text(0,0, 150, 50, "Warrior", 2)
    end
    # If we reached here we have drawn text so make the window visible.
    self.visible = true

Good luck with it AbyssalLord! :thumb:
 

khmp

Sponsor

Might I make a suggestion as well? Rather than a case statement that does a whole lot of compares and fun stuff like that. How about we utilize a Hash object? It would be a constant and it will hold two things. The variable case and the string it would print.
Code:
CLASS_VARS = {
  0 => nil,
  1 => 'Mage',
  2 => 'Rogue',
  3 => 'Warrior'
}

Then in the refresh method the case statement would be replaced by this:
Code:
if CLASS_VARS[@options].nil?
  self.visible = false
  return
end
self.contents.draw_text(0,0, 150, 50, CLASS_VARS[@options], 2)

No more adding additional cases that basically perform the same operation.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top