RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Alias Methods Help

0 Members and 1 Guest are viewing this topic.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Is there anyway to alias a method while overwriting a line or two? For example, let's say I want to re-define something like:

Code: [Select]
@viewport_a.visible = true # I want to re-define this line to @viewport_a.visible = false
Random Junk that I won't change

Is there any way that I can alter just that line without having to redefine the whole method? I know I could just use:

Code: [Select]
alias oldmethod newmethod
def oldmethod
  newmethod
  @viewport_a.visible = false
end

But @viewport_a would be visible for a fraction of a second, which is kinda irritating. So, do I just have to redefine the whole method? Or is there another way?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
It would only be visible for a fraction of a second if the method you are aliasing updates the Graphics module. Otherwise it would be fine.

To answer your question though, there is no way to alias and overwrite only a particular line. What you can do, however, is alias the visible= method of the Viewport class. It's not exactly finesse, and you would obviously need to communicate when it should or shouldn't work, but it's doable and I've done it before. Basically, in the class you are changing, you would put in an accessor variable which I would call "xyz_visible_override" or whatever, then in your alias of the method, you would first turn on the override, then call the original method, then turn off the override.

It's not very fancy but it might do the trick if it's actually necessary and it's not more trouble than it's worth. Like I said, however, the viewport would only be visible for a fraction of a second if the Graphics.update method is called in the old method. Otherwise, it's safe enough just to turn the visible switch to false after the old method has run.