Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Ryex on November 16, 2010, 01:37:56 am

Title: defined? problems
Post by: Ryex on November 16, 2010, 01:37:56 am
ok so in my DEE scripts I need the DEE to update in the game_map.update thread so I aliased the method added the update command and moved on.
but thin I needed to make a separate script that also used the DEE so I need to do the same thing but If you put both scripts in the same game the DEE would update twice every frame. this is bad obviously so I tried to make it so that the method would only be aliased once no mater how many scripts implemented the method.

if defined?(update_dee_later).nil?
  alias update_dee_later update
  def update
    $DEE.update
    update_dee_later"
  end
end


but it doesn't work
defined?(update_dee_later).nil?

returns true even after
alias update_dee_later update 

has been called
Title: Re: defined? problems
Post by: stripe103 on November 16, 2010, 03:21:41 am
In Zeriabs Quest Book 1.2 he does that with the Scene_Load alias
#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
#  Aliases and uses the on_decision method to reset $game_quests on the proper
#  time.
#==============================================================================

class Scene_Load < Scene_File
  # Check if the alias already exists (To avoid F12 errors)
  unless self.method_defined?(:zeriab_questbook_scene_load_on_decision)
    alias zeriab_questbook_scene_load_on_decision :on_decision
  end
  def on_decision(*args)
    # Call the original method
    zeriab_questbook_scene_load_on_decision(*args)
    # Check if the scene has changed
    unless $scene == self
      # Reset quest data
      $game_quests.reset
    end
  end
end


The first lines can maybe be to help
# Check if the alias already exists (To avoid F12 errors)
  unless self.method_defined?(:zeriab_questbook_scene_load_on_decision)
    alias zeriab_questbook_scene_load_on_decision :on_decision
  end


I don't know if it is right, but maybe.
Title: Re: defined? problems
Post by: Blizzard on November 16, 2010, 03:46:12 am
I thought you were supposed to use just defined?(method_name) which returns true/false depending on whether the symbol is defined or not. method_defined?(method_name) is good for checking really the method. Try it.
Title: Re: defined? problems
Post by: Ryex on November 16, 2010, 05:02:57 am
defined?(obj)
returns a string that describes what the object is, ie: expression, method etc. OR nil if it hasn't been defined yet.
I forgot about method_defined? I'll try that real quick

EDIT: YES!!! self.method_defined? worked like a charm. after working out a few minor bugs
I now have dynamic tone and weather working!