Group: Member
Posts: 52
Type: None
RM Skill: Intermediate
I keep getting an error message that pops up when I try even a simple battle test stating Game_Crafting line 259:ArgumentError wrong number of arguments (12 of 13) Anyone know what I can do to fix this?
Here is the code segment.
def createNewRecipe(stringToParse) #first check for nil and comments return nil if stringToParse == nil return nil if stringToParse.strip.empty? return nil if stringToParse.lstrip.index("#") != nil
#first parse out the text info #split at the whitespace attributes = stringToParse.split
name = attributes[0].gsub("_", " ") #the first position is name itemType = attributes[1].to_i #2nd is item type numOfIngs = attributes[2].to_i #3nd position is the num of ingredients x = 0 ingreds = [] #ingredients start at the 3rd position while x < numOfIngs number = attributes[x + 3] ingredientType = number[0,1].to_i index = number[1,number.length - 1].to_i case ingredientType #switch for ingredients when 0 ingreds.push($data_items[index]) when 1 ingreds.push($data_weapons[index]) when 2 ingreds.push($data_armors[index]) end x += 1 end y = 0 amounts = [] #amounts start after the ingredients while y < numOfIngs amounts.push(attributes[x + y + 3].to_i) y += 1 end currentIndex = x + y + 3 case itemType #switch for resulting items when 0 normalItem = $data_items[attributes[currentIndex].to_i] criticalItem = $data_items[attributes[currentIndex + 2].to_i] when 1 normalItem = $data_weapons[attributes[currentIndex].to_i] criticalItem = $data_weapons[attributes[currentIndex + 2].to_i] when 2 normalItem = $data_armors[attributes[currentIndex].to_i] criticalItem = $data_armors[attributes[currentIndex + 2].to_i] end normalAmount = attributes[currentIndex + 1].to_i critAmount = attributes[currentIndex + 3].to_i critChance = attributes[currentIndex + 4].to_i difficulty = attributes[currentIndex + 5].to_i bonusStat = attributes[currentIndex + 6].to_i bonusInterval = attributes[currentIndex + 7].to_i category = attributes[currentIndex + 8].to_i
#next, create the Recipe object, initialize it and return it! thisRecipe = Recipe.new(name, ingreds, amounts, normalItem, normalAmount, <===This is line 259 criticalItem, critAmount, critChance, difficulty, bonusStat, bonusInterval, category) return thisRecipe end
#---------------------------------------------------------------------------- # Returns the array of recipes that are available #---------------------------------------------------------------------------- def recipeList return @recipes end
#---------------------------------------------------------------------------- # Discovers the recipe at recipeIndex #---------------------------------------------------------------------------- def discover(recipeIndex) @recipes[recipeIndex].setDiscovered end
#---------------------------------------------------------------------------- # Returns the difficulties of the specified stat #---------------------------------------------------------------------------- def difficulties(stat) case stat when 0 return @atkThresholds when 1 return @defThresholds when 2 return @spiThresholds when 3 return @agiThresholds end end
Group: Member
Posts: 34
Type: Scripter
RM Skill: Advanced
In the script, there should be a line saying "class Recipe". Underneath that declaration, there'll be the "initialize" method. Check the arguments in that method, and post them here, in context (i.e., the entire initialize method)
Group: Member
Posts: 52
Type: None
RM Skill: Intermediate
QUOTE (Pacman @ Mar 18 2012, 03:45 AM)
In the script, there should be a line saying "class Recipe". Underneath that declaration, there'll be the "initialize" method. Check the arguments in that method, and post them here, in context (i.e., the entire initialize method)
if File.exists?(fileName) recipeFile = File.new(fileName, "r") buildRecipeList(recipeFile) exportData else @recipes = load_data("Data/recipes.rf") end end
def buildRecipeList(recipeFile) while (line = recipeFile.gets) thisRecipe = createNewRecipe(line) @recipes.push(thisRecipe) unless thisRecipe == nil end end
def exportData fileName = "Data/recipes.rf" if File.exists?(fileName) File.delete(fileName) end file = File.new(fileName, "wb") Marshal.dump(@recipes, file) end #---------------------------------------------------------------------------- # returns a new Recipe object. the recpies.txt file should have data in the # following format: # # name: Name of the item being created # itemType: 0 for item, 1 for weapon, 2 for armor. The normal # and critical form MUST be the same item type! # numOfIngs: number of different ingredients from 1 to 9 # ingreds 01..2999: the item indexes of the ingredients. the first # character determines the item type for each # ingredient. 0 for item, 1 for weapon, 2 for armor # amounts 1..999: amount of each ingredient # normalItem: index of item created on normal success # normalAmount: amount of normal item created on success # criticalItem: item created from a critical success # critAmount: amount of crit item created # critChance: chance to crit (out of 100) # difficulty: integer 0 to 9 where 0 is easiest and 9 is hardest # bonusStat: The statistic that will be used to calculate the # bonus critical chance. 0 for attack, 1 for defense, # 2 for spirit, 3 for agility. # bonusInterval: The amount of the bonus stat it takes to get a 1% # higher critical chance # category: The type of crafting (smithing, woodworking, etc.) # As an integer from 0 to 9! # # The file allows for empty lines and comments using '#' to start a line # Here's some example lines from the file: # # #Leather Working # Rough_Leather 0 1 0204 2 205 1 205 3 10 0 2 10 1 # # NOTE: whitespace in the name must be replaced with underscores!!! # #---------------------------------------------------------------------------- def createNewRecipe(stringToParse) #first check for nil and comments return nil if stringToParse == nil return nil if stringToParse.strip.empty? return nil if stringToParse.lstrip.index("#") != nil
#first parse out the text info #split at the whitespace attributes = stringToParse.split
name = attributes[0].gsub("_", " ") #the first position is name itemType = attributes[1].to_i #2nd is item type numOfIngs = attributes[2].to_i #3nd position is the num of ingredients x = 0 ingreds = [] #ingredients start at the 3rd position while x < numOfIngs number = attributes[x + 3] ingredientType = number[0,1].to_i index = number[1,number.length - 1].to_i case ingredientType #switch for ingredients when 0 ingreds.push($data_items[index]) when 1 ingreds.push($data_weapons[index]) when 2 ingreds.push($data_armors[index]) end x += 1 end y = 0 amounts = [] #amounts start after the ingredients while y < numOfIngs amounts.push(attributes[x + y + 3].to_i) y += 1 end currentIndex = x + y + 3 case itemType #switch for resulting items when 0 normalItem = $data_items[attributes[currentIndex].to_i] criticalItem = $data_items[attributes[currentIndex + 2].to_i] when 1 normalItem = $data_weapons[attributes[currentIndex].to_i] criticalItem = $data_weapons[attributes[currentIndex + 2].to_i] when 2 normalItem = $data_armors[attributes[currentIndex].to_i] criticalItem = $data_armors[attributes[currentIndex + 2].to_i] end normalAmount = attributes[currentIndex + 1].to_i critAmount = attributes[currentIndex + 3].to_i critChance = attributes[currentIndex + 4].to_i difficulty = attributes[currentIndex + 5].to_i bonusStat = attributes[currentIndex + 6].to_i bonusInterval = attributes[currentIndex + 7].to_i category = attributes[currentIndex + 8].to_i
#next, create the Recipe object, initialize it and return it! thisRecipe = Recipe.new(name, ingreds, amounts, normalItem, normalAmount, criticalItem, critAmount, critChance, difficulty, bonusStat, bonusInterval, category) return thisRecipe end
#---------------------------------------------------------------------------- # Returns the array of recipes that are available #---------------------------------------------------------------------------- def recipeList return @recipes end
#---------------------------------------------------------------------------- # Discovers the recipe at recipeIndex #---------------------------------------------------------------------------- def discover(recipeIndex) @recipes[recipeIndex].setDiscovered end
#---------------------------------------------------------------------------- # Returns the difficulties of the specified stat #---------------------------------------------------------------------------- def difficulties(stat) case stat when 0 return @atkThresholds when 1 return @defThresholds when 2 return @spiThresholds when 3 return @agiThresholds end end
#---------------------------------------------------------------------------- # Returns the array of required tools for the specified category #---------------------------------------------------------------------------- def tools(category) return @requiredTools[category] end