[XP] Inheritance
#11
Ok, it tried a new p command right after my block tests if Shift is pressed and still nothing. that means that my entire class that aliases scene_item is not working...
Reply }
#12
Place your p command before and after your alias statement. Different text of course.

If it executes before but not after your alias, then it has something to do with the method you're using. If it executes both print statements, then your method is running through all the statements.

And if neither execute... um... WHAT?
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#13
Sorry if I cut in without reading the whole thread. I'm answering to the initial question here. When an inherited class defines a method that exists in the base class, it can use the reserved word super to call the base class version of the method. Aliasing isn't necessary if you can use this technique in your code.
[Image: f7d70f7d-d21f-470a-b93d-fa23cfcfaeb5_zpsfe7368c0.png] [Image: facebook_icon.png] [Image: youtube_128x128-120x120.png] [Image: deviant.png] [Image: save-point.png]
Reply }
#14
i have tried super and i tried using p at different points. simply put, none of my methods are being used, though the class is being called just fine. I placed a p command outside the methods and the game displayed it. so this just will NOT work unless it is actually pasted into Scene_item, evidently. I dont understand. I thought alias could take an existing method and add to it without editing the script directly... I figured super would call the original code in the super classes method of the same name, and then run the new code.... Maybe i just dont get it
Reply }
#15
ok, so I played around with changing the color of the title HP in Window_BattleStatus so that when in battle, 'HP' is shown green. this was just a simple way to try to alias methods, though Im not sure if this is done correctly.

This DOES change the Name of 'HP', but I am curious if this would be no-no for compatibility? Essentially, I re-wrote def refresh so that it calls my method draw_colored_hp instead of draw_actor_hp.

Basically, in terms of compatibility and/or scripting ettiquette, is this acceptable?

Man, I suck at this!
[/i]
Reply }
#16
By compatibility standards, it is a no-no. However, thanks for noting it and asking. We do prefer to use alias whenever possible. BUT... if RPGMaker's database editor does not allow you to change words like STR, DEX, HP, Gold, and the like, what choice DO you have?

When you make a script, it would be good to let anyone using it know what methods you rewrote. That way they would know what's up if they experience a problem.

I prefer to add a configuration section in my scripts to allow the end user (ie you) to be able to change my custom texts... if needed. Using a config section is easy enough. Working on making a good one... practice practice practice.

EDIT: *DerVVulfman now looks at the script*

EDIT 2: Remember how we talked about inheritance and that one script inherits the methods from another?

Window_Battlestatus inherits the draw_HP command from Window_Base... the class that defined it. However, if you have your own 'draw_actor_hp' in the Window_Battlestatus class, it only affects that class. Your menus and all other HP drawing systems will still use the default one.

You coulda just use the whole thingie. ^_^
Yeah, that's being lazy... Laughing + Tongue sticking out
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#17
I figured it out. My problem was how I was aliasing the methods. I wasnt calling the old method correctly, but now that I learned, I have adapted my script. In fact, it has allowed me to finish my first script which I will post here shortly.
Reply }
#18
Ah, be forewarned about aliases. They are tricky devils.

Picture an method like this:
Code:
def method_one(x)
  return_val = x + 3
  return x
end

It adds 3 to what is entered. And then returns it. Aliasing this should be like this...

Code:
alias new_method_one method_one
def method_one(x)
  value_new = new_method_one(x)
  value_new += 40
  return value_new
end

This new alias retrieves the value gained from the original method, and then adds 40 to it before returning it. This way, you can alter values that are generated and returned by methods.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#19
Another thing that you might be careful: don't use aliases with methods that exists only on the parent classes.

#Wrong
Code:
class Parent_Class
  def method(*args)
     #anything
  end
end
class Child_Class < Parent_Class
  alias old_method method
  def method(*args)
    old_method(*args)
     #anything
  end
end
This will return the stack level too deep error if you press F12.

Instead use the super
Code:
class Parent_Class
  def method(*args)
     #anything
  end
end
class Child_Class < Parent_Class
  def method(*args)
    super(*args)
     #anything
  end
end

Reply }
#20
Ah, so is that the culprit of the dreaded F12 glitch? When I encounter and narrow the offending method, I've been wrapping them in an if...end block that Seph showed me years ago.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }




Users browsing this thread: 1 Guest(s)