defined? problems

Started by Ryex, November 16, 2010, 01:37:56 am

Previous topic - Next topic

Ryex

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
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

stripe103

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.

Blizzard

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.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

November 16, 2010, 05:02:57 am #3 Last Edit: November 16, 2010, 05:31:43 am by Ryexander
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!
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />