QuestLog error

Started by firevenge007, November 19, 2013, 03:43:51 pm

Previous topic - Next topic

firevenge007


So i've been trying to use game_guy's Quest log, but I keep on coming up with an error. If anyone knows what's going on, I'm all ears!

#===============================================================================
# Quest Log System
# Author game_guy
# Version 3.0
#-------------------------------------------------------------------------------
# Intro:
# A script that keeps track of quests you obtain and complete.
#
# Features:
# Marks quest names with a yellow color if they're completed
# Easy to setup one quest
# Be able to use a fairly long description
# Be able to display a picture
# Easy to add and complete a quest
# More compatible than earlier versions
#
# Instructions:
# Scroll down a bit until you see # Being Config. Follow the instructions there.
# Scroll below that and you'll see Begin Quest Setup. Follow the steps there.
#
# Script Calls:
# Quest.add(id) ~ Adds the quest(id) to the parties quests.
# Quest.take(id) ~ Takes the quest(id) from the party.
# Quest.complete(id) ~ Makes the quest(id) completed.
# Quest.completed?(id) ~ Returns true if the quest(id) is completed.
# Quest.has?(id) ~ Returns true if the party has quest(id).
#
# Credits:
# game_guy ~ for making it
# Beta Testers ~ Sally and Landith
# Blizzard ~ Small piece of code I borrowed from his bestiary
#===============================================================================
module GameGuy
 #==================================================
 # Begin Config
 # UsePicture ~ true means it'll show pictures in
 #              the quests, false it wont.
 #==================================================
 UsePicture   = false
 
 def self.qreward(id)
   case id
   #==================================================
   # Quest Reward
   # Use when x then return "Reward"
   # x = id, Reward = reward in quotes
   #==================================================
   when 1 then return "100 Gold"
   when 2 then return "3 Potions"
   when 3 then return "Strength Ring"
   end
   return "????"
 end
 
 def self.qpicture(id)
   case id
   #==================================================
   # Quest Picture
   # Use when x then return "picture"
   # x = id, picture = picutre name in quotes
   #==================================================
   when 1 then return "ghost"
   end
   return nil
 end
 
 def self.qname(id)
   case id
   #==================================================
   # Quest Name
   # Use when x then return "name"
   # x = id, name = quest name in quotes
   #==================================================
   when 1 then return "Bob's Chicken"
   when 2 then return "Lost My Weapon"
   when 3 then return "Finding The Letter"
   when 4 then return "Do You Believe in Magic"
   when 5 then return "Quest For A Bowl"
   when 6 then return "Quest For Quest"
   when 7 then return "Rat Catcher"
   when 8 then return "Baby Trouble"
   when 9 then return "Monster Mother"
   when 10 then return "Purity of Water"
   when 11 then return "Sailor's Quest"
   when 12 then return "Dangerous Passage"
   when 13 then return "The Search For Hidden Treasure"
   when 14 then return "Pricilla's Possession"
   when 15 then return "Agilequest"
   when 16 then return "Quest of the Musaph"
   when 17 then return "The Urothmyte Trials"
   when 18 then return "Bar Fight!"
   when 19 then return "Abandoned Village"
   when 20 then return "Milk Quest Part 1"
   when 21 then return "Milk Quest Part 2"
   when 22 then return "Milk Quest Part 3"
   when 23 then return "Herbalist Dungeon"
   when 24 then return "Expidition To The Danger Zone"
   when 25 then return "Angel Flight"
   when 26 then return "Combat Guild"
   when 27 then return "Leothon's Mini-Quest"
   when 28 then return "Warped Diamond"
   when 29 then return "Fortune"
   when 30 then return "The Mysterious Source"
   end
   return ""
 end
 
 def self.qlocation(id)
   case id
   #==================================================
   # Quest Location
   # Use when x then return "location"
   # x = id, location = location in quotes
   #==================================================
   when 1 then return "Arton Woods"
   when 2 then return "Eeka"
   when 3 then return "Eeka"
   end
   return "????"
 end
 
 def self.qdescription(id)
   case id
   #==================================================
   # Quest Description
   # Use when x then return "description"
   # x = id, description = quest description in quotes
   #==================================================
   when 1 then return "Capture 10 animals and bring back the meat."
   when 2 then return "Bring gold to Jarns Defense to pay her tab."
   when 3 then return "Go get Kip a hunting knife from Eeka."
   end
   return ""
 end
 
end

module Quest
 
 def self.add(id)
   $game_party.add_quest(id)
 end
 
 def self.take(id)
   $game_party.take_quest(id)
 end
 
 def self.complete(id)
   $game_party.complete(id)
 end
 
 def self.completed?(id)
   return $game_party.completed?(id)
 end
 
 def self.has?(id)
   return $game_party.has_quest?(id)
 end
 
end
 
class Game_Party
 
 attr_accessor :quests
 attr_accessor :completed
 
 alias gg_quests_lat initialize
 def initialize
   @quests = []
   @completed = []
   gg_quests_lat
 end
 
 def add_quest(id)
   unless @quests.include?(id)
     @quests.push(id)
   end
 end
 
 def completed?(id)
   return @completed.include?(id)
 end
 
 def complete(id)
   unless @completed.include?(id)
     if @quests.include?(id)
       @completed.push(id)
     end
   end
 end
 
 def has_quest?(id)
   return @quests.include?(id)
 end
 
 def take_quest(id)
   @quests.delete(id)
   @completed.delete(id)
 end
 
end
class Scene_Quest
 def main
   @quests = []
   for i in $game_party.quests
     @quests.push(GameGuy.qname(i))
   end
   @map = Spriteset_Map.new
   @quests2 = []
   for i in $game_party.quests
     @quests2.push(i)
   end
   @quests.push("No Quests") if @quests.size < 1
   @quests_window = Window_Command.new(160, @quests)
   @quests_window.height = 480
   @quests_window.back_opacity = 110
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   @quests_window.dispose
   @quest_info.dispose if @quest_info != nil
   @map.dispose
 end
 def update
   @quests_window.update
   if @quests_window.active
     update_quests
     return
   end
   if @quest_info != nil
     update_info
     return
   end
 end
 def update_quests
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Menu.new
     return
   end
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     @quest_info = Window_QuestInfo.new(@quests2[@quests_window.index])
     @quest_info.back_opacity = 110
     @quests_window.active = false
     return
   end
 end
 def update_info
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @quests_window.active = true
     @quest_info.dispose
     @quest_info = nil
     return
   end
 end
end
class Window_QuestInfo < Window_Base
 def initialize(quest)
   super(160, 0, 480, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   @quest = quest
   refresh
 end
 def refresh
   self.contents.clear
   if GameGuy::UsePicture
     pic = GameGuy.qpicture(@quest)
     bitmap = RPG::Cache.picture(GameGuy.qpicture(@quest)) if pic != nil
     rect = Rect.new(0, 0, bitmap.width, bitmap.height) if pic != nil
     self.contents.blt(480-bitmap.width-32, 0, bitmap, rect) if pic != nil
   end
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, 480, 32, "Quest:")
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 32, 480, 32, GameGuy.qname(@quest))
   self.contents.font.color = system_color
   self.contents.draw_text(0, 64, 480, 32, "Reward:")
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 96, 480, 32, GameGuy.qreward(@quest))
   self.contents.font.color = system_color
   self.contents.draw_text(0, 128, 480, 32, "Location:")
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 160, 480, 32, GameGuy.qlocation(@quest))
   self.contents.font.color = system_color
   self.contents.draw_text(0, 192, 480, 32, "Completion:")
   self.contents.font.color = normal_color
   if $game_party.completed.include?(@quest)
     self.contents.font.color = crisis_color
     self.contents.draw_text(0, 224, 480, 32, "Completed")
   else
     self.contents.font.color = normal_color
     self.contents.draw_text(0, 224, 480, 32, "In Progress")
   end
   self.contents.font.color = system_color
   self.contents.draw_text(0, 256, 480, 32, "Description:")
   self.contents.font.color = normal_color
   text = self.contents.slice_text(GameGuy.qdescription(@quest), 480)
   text.each_index {|i|
       self.contents.draw_text(0, 288 + i*32, 480, 32, text[i])}
 end
end
class Bitmap
 
 def slice_text(text, width)
   words = text.split(' ')
   return words if words.size == 1
   result, current_text = [], words.shift
   words.each_index {|i|
       if self.text_size("#{current_text} #{words[i]}").width > width
         result.push(current_text)
         current_text = words[i]
       else
         current_text = "#{current_text} #{words[i]}"
       end
       result.push(current_text) if i >= words.size - 1}
   return result
 end
 
end

Script 'QuestLog' line 205: NoMethodError occured. undefined method 'each' for nil:NilClass



class Scene_Quest
 def main
   @quests = []
   for i in $game_party.quests <---- this is line 205
     @quests.push(GameGuy.qname(i))
   end
   @map = Spriteset_Map.new
   @quests2 = []
   for i in $game_party.quests
     @quests2.push(i)
   end



Thanks for your time.

G_G

My only guess is you're trying to use this with an old save game. Or you have another script that's overriding Game_Party.

firevenge007

Why does it not work in conjunction with old save games?

R.A.V.S.O

Quote from: firevenge007 on November 19, 2013, 10:10:59 pm
Why does it not work in conjunction with old save games?


Possibly because between now and the last time you saved your game the scripts that you used or configured changed considerably,
when you saved your game it probably saved such configuration as well, and thus the old save when loaded tries to execute with
the old script's configuration,
if changed drastically it will probably stop and throw an error similar to that one.

most (not all) scripts tend to do this when desynchronized from their saves (at least those that change the system drastically)
so when doing major changes to the scripts a game frequently uses it is recommended to re-start the gameplay from the beginning
to avoid these collisions,

I believe this is also why some scripters here place a neat yet helpful warning about how some scripts might corrupt or downright not
work with previous scripts.
Personality Test results
Spoiler: ShowHide




"Life is unfair, so make it unfair in your favor" -Sesilou

G_G

Quote from: firevenge007 on November 19, 2013, 10:10:59 pm
Why does it not work in conjunction with old save games?


Because, when you save your game before you implement quest logs, the data "quests" doesn't exist within your save data file. So when you go to load it, the script loads your Game_Party information, and since quests doesn't exist within it yet, it gets treated as "nil". Quests gets created in the initialize method of Game_Party, which is only called upon when creating a new game. So a lot of times when implementing new scripts, if it doesn't work on loading a save, try it in a new game.

firevenge007

Is there any way to have it work with loaded games then? Some kind of add-on that adds Quests to loaded files?

Only reason I'm asking this is because whenever I update my game, the players of my game take their save file and put it in the new game folder, which updates the game with the new content. But if it doesn't work, then the players will get an error.

It's not detrimental to the game, I was just wondering if there is a way to make it work.

KK20

Quote from: R.A.V.S.O on November 19, 2013, 10:38:33 pm
Possibly because between now and the last time you saved your game the scripts that you used or configured changed considerably

That would be a possible case if G_G updated the script recently. But it's been ~2 years since the last edit so that's a no.

I think

class Scene_Load < Scene_File

  alias load_party_variables on_decision
  def on_decision(filename)
    load_party_variables(filename)
    # Initializes quest variables to empty arrays UNLESS they are not nil to begin with
    $game_party.quests ||= []
    $game_party.completed ||= []
  end

end

Can be placed anywhere in the quest script.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Huh. I never thought about it that way.

KK20

Me neither. That is until 5 seconds before I started writing the snippet. :P

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!