Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Jaiden on October 30, 2017, 05:55:24 pm

Title: [XP][Resolved] "Comparison of Fixnum with Nil Failed"
Post by: Jaiden on October 30, 2017, 05:55:24 pm
I am getting an error with ForeverZer0's Blacksmith script (the fixed version by KK20):
http://forum.chaos-project.com/index.php/topic,6171.0.html
(I didn't want to necropost, and I'm not sure if it's the script as much as it's a conflict)

It's giving me the following error:
(https://i.imgur.com/8paeL3v.png)

In the following method:
Spoiler: ShowHide
  def self.materials?(type, id)
    # Get the required materials for the item
    materials = case type
    when 0 then [self.weapon_forges(id), self.weapon_gold(id)]
    when 1 then [self.armor_forges(id), self.armor_gold(id)]
    when 2 then [self.item_forges(id), self.item_gold(id)]
    end
    materials[0] = [] if materials[0] == nil
    # Check gold, skipping item check if there is not enough.
    if $game_party.gold >= materials[1][0]
      # Iterate all required materials, making sure enough are in inventory.
      materials[0].each {|item|
        # Branch by the type of the item.
        result = case item[0]
        when 0 then ($game_party.weapon_number(item[1]) >= item[2])
        when 1 then ($game_party.armor_number(item[1]) >= item[2])
        when 2 then ($game_party.item_number(item[1]) >= item[2])
        end
        # End iteration and return false immidiately if missing required item.
        return false unless result
      }
      return true
    end
    return false
  end


Here is my config:
Spoiler: ShowHide
module Blacksmith
 
#===============================================================================
#                          BEGIN CONFIGURATION
#===============================================================================

  FORGE_SE = ['006-System06', 80, 100]
  # SE played when an item is forged. ['FILENAME', VOLUME, PITCH]
  EXTRACT_SE = ['020-Teleport03', 80, 100]
  # SE played when an item extraction is performed. ['FILENAME', VOLUME, PITCH]
  ENCHANT_SE = ['020-Teleport03', 80, 100]
  # SE played when an item enchantment is performed. ['FILENAME', VOLUME, PITCH]
 
  USE_ENCHANTMENTS = true
  # Set to true to enable the "Enchant" feature of the system.
 
  NO_ENCHANT_WEAPONS = []
  NO_ENCHANT_ARMORS = []
  # Include IDs of any equipment that cannot be enchanted in the respective
  # arrays, seperating by commas. Ignore these if not using enchant feature.
 
  # Define the colors used for the text in the Blacksmith shop.
  PLUS_COLOR = Color.new(128, 255, 128)
  MINUS_COLOR = Color.new(255, 128, 128)
 
  MAP_BACK = true
  # Set to true if you would like slightly opaque windows with the map showing
  # through.
 
  #-----------------------------------------------------------------------------
  # FORGE DATABASE
  #-----------------------------------------------------------------------------
  # Define the materials used for each weapon/armor/item that can be forged and
  # extracted. They configuration is slightly different than what it was in the
  # first version of the script. You can seperately define materials that are
  # given during extraction if you like, or ignore it and it will simply return
  # the same materials it takes to forge them. It works like this:
  #
  # STEP 1:
  #   Create a new "case" in the appropriate method below for the type of item
  #   you are trying to define. There are three of them, one each for weapons,
  #   armors, and items. Just use this syntax:
  #       
  #          when DATABASE_ID then []
  #
  # STEP 2:
  #   Now you can begin to add materials to forge the item. Each material has
  #   an number which defines what type of item is is. Here is the "key":
  #
  #       0 = Weapon
  #       1 = Armor
  #       2 = Item
  #
  #   To define a material for an item, you simply create a three element array
  #   using this format:
  #                       [ITEM_TYPE, DATABASE_ID, QUANTITY]
  #
  #   ...and add it the appropriate empty array in the case statement you made
  #   in Step 1. You can add as many different items as you please to forge an
  #   weapon/armor/item, simply seperate the material arrays with commas. See
  #   below for a few examples.
  #-----------------------------------------------------------------------------
  def self.weapon_forges(id)
    return case id
    when 1 then [[2, 33, 3]]            # Bronze Sword
    end
  end
 
  def self.armor_forges(id)
    return case id
    when 1 then [[2, 33, 5]]
    end
  end
 
  def self.item_forges(id)
    return case id
    when 2 then [[2, 33, 5]]
    end
  end
 
  #-----------------------------------------------------------------------------
  # EXTRACT DATABASE
  #-----------------------------------------------------------------------------
  # Here you can define the items received when a specific item is extracted.
  # It can be setup the same as way as above. Items left undefined will return
  # the same items that are required to forge it. You can define an item with an
  # empty array to have it return no items, though it can still return gold.
  #-----------------------------------------------------------------------------
  def self.weapon_extractions(id)
    return case id
    when 1 then [[2, 33, 1], [2, 42, 1]]
    else
      self.weapon_forges(id)
    end
     
  end
 
  def self.armor_extractions(id)
    return case id
    when 1 then [[2, 34, 2], [0, 1, 1]]
    else
      self.armor_forges(id)
    end
  end
 
  def self.item_extractions(id)
    return case id
    when 1 then []                     # Potion
    when 2 then [[2, 1, 2]]            # High Potion
    when 3 then [[2, 2, 2], [2, 1, 2]] # Full Potion
    when 4 then []                     # Perfume
    when 5 then [[2, 4, 2]]            # High Perfume
    when 6 then [[2, 4, 2], [2, 5, 2]] # Full Perfume
    else
      self.item_forges(id)
    end
  end
 
  #-----------------------------------------------------------------------------
  # GOLD DATABASE
  #-----------------------------------------------------------------------------
  # Here you can define the amount of gold that is required to forge an item,
  # and the amount that is given if extracted. There are three methods, one each
  # for weapons, armors, and items. Simply follow this pattern for each
  # category:
  #
  #     when DATABASE_ID then [FORGE_PRICE, EXTRACT_GOLD,]
  #-----------------------------------------------------------------------------
  def self.weapon_gold(id)
    return case id
    when 1 then [200, 50]
    when 2 then [450, 225]
    else
      [0, 0]
    end
  end
 
  def self.armor_gold(id)
    return case id
    when 1 then []
    when 2 then []
    when 3 then []
    when 4 then []
    when 5 then []
    else
      [0, 0]
    end
  end
 
  def self.item_gold(id)
    return case id
    when 1 then [100, 0]
    else
      [0, 0]
    end
  end
 
  #-----------------------------------------------------------------------------
  # ENCHANT DATABASE
  #-----------------------------------------------------------------------------
 
  #-----------------------------------------------------------------------------
  # Here you can define what items will alter stats when used to enchant with.
  # You need to create a two element array, and add it to the respective array
  # below that corresponds with the desired item.
  #
  # ex.
  #     when ITEM_ID then [[KEYWORD, VALUE], [KEYWORD, VALUE]]
  #
  #     KEYWORD: See below for a list of possible keywords. Stat changes that
  #              can affect only weapons will have no effect on armors, and
  #              vice-versa.
  #     VALUE : The amount by which to change the stat. Negative values will
  #             lower the stat.
  #-----------------------------------------------------------------------------
  # KEYWORDS:
  #
  #   'ATK' (Weapon Only)           'DEX'               'PDEF'
  #   'EVA' (Armor Only)            'AGI'               'MDEF'
  #   'STR'                         'INT'   
  #
  #   ** Keywords have to be written EXACTLY as they appear.
  #   ex: when 40 then [['STR', 15], ['ATK', 5]] # Behemoth Juice
  #-----------------------------------------------------------------------------
  def self.enchant_stats(item_id)
    return case item_id
    when 1 then []
    #Enter stats here
    end
  end
 
  #-----------------------------------------------------------------------------
  # Define state altering enchantments.
  #
  # ex.
  #     when ITEM_ID then [[VALUE, STATE_ID], [VALUE, STATE_ID]]
  #
  #     VALUE: One of three different values to represent states efficiency.
  #              -1 = Minus state (Does nothing on armors)
  #               0 = Neutral
  #               1 = Plus state
  #     STATE_ID: The ID in the database of the state.
  #-----------------------------------------------------------------------------
  def self.enchant_states(item_id)
    return case item_id
    when 1 then []
    #when 38 then [[1, 2], [1, 4], [1, 6]] # Chaos Orb
    end
  end
 
  #-----------------------------------------------------------------------------
  # Define element altering enchantments.
  #
  # ex.
  #     when ITEM_ID then [[VALUE, ELEMENT_ID], [VALUE, ELEMENT_ID]]
  #
  #     VALUE: One of two different values to represent element efficiency.
  #              true  = Uses element
  #              false = Doesn't use element (Negates element if present)
  #     ELEMENT_ID: The ID in the database of the element.
  #-----------------------------------------------------------------------------
  def self.enchant_elements(item_id)
    return case item_id
    when 1 then []
    #when 36 then [[true, 3], [false, 5]] # Amethyst
    #when 37 then [[true, 1]]             # Ruby ;)
    end
  end 
 
  #-----------------------------------------------------------------------------
  # Define the amount of gold it takes to enchant a weapon or armor with the
  # item.
  #-----------------------------------------------------------------------------
  def self.enchant_gold(item_id)
    return case item_id
    when 1 then []
    #when 36 then 1500
    else
      0
    end
  end
 
#===============================================================================
#                              END CONFIGURATION
#===============================================================================
 


I tried troubleshooting with puts and I found that "materials[0][1]" is nil but I'm not sure why. materials[0] and materials[1] are both normal values. I have a feeling it's a script conflict, as I've got quite a few in my game now.

Thanks!
Title: Re: [XP] "Comparison of Fixnum with Nil Failed"
Post by: KK20 on October 30, 2017, 06:13:12 pm
You need to provide a gold amount for your armors. Leaving it as an empty array won't do you any good.
Title: Re: [XP] "Comparison of Fixnum with Nil Failed"
Post by: Jaiden on October 30, 2017, 06:36:46 pm
 :facepalm: :facepalm: :facepalm:

Thank you.