The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: modern algebra on May 17, 2007, 10:51:45 PM

Title: Overwriting Partial Code
Post by: modern algebra on May 17, 2007, 10:51:45 PM
Just wondering:

Is it possible to overwrite parts of a code without overwriting the entire method?

I.E. If we have a method like this


def method
  for i in 100...110
    p i
  end
  p "done"
end

and you wanted to overwrite p "done" and change it to p "complete", but wanted to leave everything above it as it is and you don't want to rewrite the entire method.

Is that possible?


Title: Re: Overwriting Partial Code
Post by: Tsunokiette on May 17, 2007, 11:46:43 PM
You should re-write it into the following. (A more compatible method)

def method
  for i in 100...110
    p i
  end
end


Then in the class you want to re-define it, do -

alias: name_refering_to_original_method: method
def method
      name_refering_to_original_method
      p "Complete"
end
Title: Re: Overwriting Partial Code
Post by: modern algebra on May 18, 2007, 01:12:11 AM
Thanks, but the reason I wanted it was so for my scripts, if I had to do minor modifications to the default scripts (but ones that required some overwriting, so not straight additions), I could just do it in a code snippet, thus making it easier to share the scripts.

Unfortunately, your method would still involve rewriting part of the default scripts  ;9

Thanks anyway though.
Title: Re: Overwriting Partial Code
Post by: Zeriab on May 18, 2007, 08:24:09 AM
One of the goals of the SDK is to split many of the default scripts up into a lot of methods thus allowing easier customization.
This naturally causes a lot of compatibility problems, but meh.

Anyway. You might be able to modify the parse tree directly or you might be able to read and modify the original method in question.
If you are able to either of these ways it will probably not be simple what you have to do. I'm only guessing, I haven't researched.