Chaos Project

RPG Maker => General Discussion => Topic started by: Heretic86 on April 20, 2012, 03:52:25 am

Title: General Scripting Question...
Post by: Heretic86 on April 20, 2012, 03:52:25 am
I wrote a script that I found I needed to fully redefine the entire method.  What I did works for the specific purposes I was aiming for, however, as a budding scripter, I'd like to make sure my scripts are as compatible with other scripts as possible.  It doest really matter what my script is, but what I'd like to know, in general, is doing a full redefinition of one of the default scripts a "bad" way to do smaller simpler scripts, or do you have any recommendations, like dont alias, or always alias, or never do full def rewrites, anything to that effect?
Title: Re: General Scripting Question...
Post by: Blizzard on April 20, 2012, 04:06:16 am
You should alias whenever possible to ensure maximum compatibility. If you need additional parameters in a function, you should then add default values so that other scripts using the previous definition of the method can still function normally when called without your additional parameters.

Sometimes methods need to be rewritten completely because their core functionality was changed. This is a situation where aliasing doesn't make not much sense since the previous code needs to be overwritten completely.

Basically you use aliasing when you want to "extend" the original code. If you have to rewrite it completely, alias doesn't help you.
Title: Re: General Scripting Question...
Post by: Heretic86 on April 20, 2012, 04:09:53 am
WHen I get a chance this weekend, I wanna post an updated Screen_Z method that I wrote, which allows large sprites to render as Flat on the Ground.  Added some other stuff into it too, but just wanna see if you think it is worth while.  Have to do this weekend as I have to extract the code from another larger script im working on.
Title: Re: General Scripting Question...
Post by: Calintz on April 20, 2012, 05:22:48 am
i understand what an alias' does and how they're extremely useful, but i guess i'm having trouble knowing exactly what needs to be aliased. do you apply the alias to the class itself so that all methods of the class remain as is without changes, or do you alias the particular method from inside the class? i guess i'm asking because def initalize is used in EVERY window, so how do you alias an initialize method for a window that is a subclass without changing the original script?
Title: Re: General Scripting Question...
Post by: Ryex on April 20, 2012, 05:48:21 am
you really should never alias an init method, if you need to then your probably better off making a subclass and using the super method. But, like every rule there are exceptions in thous cases alias still works like normal no special treatment needed. an alias only applies to the current scope or only the class in which it is used/all subclasses.
Title: Re: General Scripting Question...
Post by: Calintz on April 20, 2012, 06:14:26 am
got ya! thank you Ryex.
Title: Re: General Scripting Question...
Post by: Blizzard on April 20, 2012, 06:18:43 am
I disagree. I've aliased the initialize method many, many times because that's what I needed. e.g. When I had to add a new parameter for actors, I added it in Game_Actor#initialize.
Title: Re: General Scripting Question...
Post by: G_G on April 20, 2012, 08:27:20 am
I've done it various times as well, especially to Game_System or Game_Party when I'm adding new variables. Its not bad to alias the initialize method.
Title: Re: General Scripting Question...
Post by: Heretic86 on April 20, 2012, 10:26:19 am
Wouldnt aliasing initialize make them More compatible with other scripts?  For example, you add a new property, but aliased init so another script that also aliases init to add a different new property allow for both additional scripts to have both of their new properties?  Not that much experience here so feel free to fill me in, but maybe I should ask why I shouldnt alias an initialize?  Maybe an example would help?
Title: Re: General Scripting Question...
Post by: Blizzard on April 20, 2012, 10:41:35 am
No, you're right about that. That's what G_G and me basically said. I think Ryex probably just confused it with another method. xD
Title: Re: General Scripting Question...
Post by: Calintz on April 20, 2012, 08:15:00 pm
food for thought.