Main Menu
  • Welcome to The RPG Maker Resource Kit.

Overwriting Partial Code

Started by modern algebra, May 17, 2007, 10:51:45 PM

0 Members and 1 Guest are viewing this topic.

modern algebra

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?



Tsunokiette

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
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

modern algebra

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.

Zeriab

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.