[XP] Inheritance
#1
Hey everyone,
I have a question about inheritance. If a new class has inherited from a RTP (or standard) class, it gets all the methods, so I believe...
However, if I just want to add to that method, do I have to define it again and list only the additions? or define it and list the entire method + additions? or am I supposed to alias it and just add the additions? (basically, I know what alias is supposed to do, but no real clue how to use it yet.)

for example
Im such a noob at this...
Reply }
#2
You wouldn't want to inherit from a more complex class like Scene_Item, as it is designed specifically to create an item menu. But if you are using the RMXP SDK, they created a Scene_Main which is a skeleton which you can inherit from. It would fill in the blanks for things like main, update... stuff you don't need to recreate.

It is like how the window classes (Window_Selectable, Window_Help) inherit basic features from Window_Base... that way you don't have to recreate the text_color, normal_color and the like methods.

BUT... if you do perform an inherit, like 'Window_Fred < Window_Base', you can still recreate your own methods. What I mean is .... Hehe... FRED here inherits the methods from Window_Base. But if I wanted to have a different def normal_color method, I could add it in. My 'new normal_color' only shows in the Fred window while all the other windows would use the default one.

Also, there's a command called 'Alias' that you may like to learn about. It attaches code to existing methods.

Like... hrm...

Code:
class Window_PlayTime < Window_Base
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  alias new_refresh refresh
  def refresh
    self.contents.font.name = "Times New Roman"
    new_refresh
  end
end

This little scriptette adds a statement that changes the font for that particular window, and then runs the regular 'refresh' method. This saves you the effort of retyping the whole thing.

It'll take some practice. But hey... you're starting.
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 }
#3
I am actually working with getting information from Scene_Item, so its necessary.
so I do not need to add the entire method. I could really save some time with this. and it is better for compatibility, right?

EDIT: So I tried this out. I figured I would test Jackatrades Item Detail script, since it is one I know edits an existing scene and has errors with some other scripts that utilize Scene_Item. So I go and I created a class called
Code:
class Scene_IDView < Scene_Item
I aliased the methods he edited, then cut and pasted the individual code into my class. I then replaced Scene_Item with a copy from a new project. all the methods are there still (except update_detail, which i just put into my class) when I tested, the detail window wont come up. so I must not be aliasing them correctly, as it worked before (it WAS his demo at one point... ) example alias:
Code:
alias new_update update
  def update
    
    $currenthighlighteditem = @item_window.item
    if @itemdetail_window.active
      update_detail
      return
    end
    new_update
  end
am I doing something wrong?
EDIT2: (but at least I didnt get method or syntax errors!)
Reply }
#4
I cannot say what was or wasn't wrong from such a snippet.

You're grabbing the current item from the item menu and storing it in currenthighlighteditem
Then you perform a routine that runs item_detail if the item detail window is active.
Then it exits the update method IF you are only dealing with the item detail window.
Then runs the rest of the system.

Other than that, it may not be a case of syntax error, but logical error which is about the way and order things are performed in a program.

But, the Item_Detail script by Jackatrades (man, it's been YEARS since I talked to him in Creation Asylum...), is one of the first I really... REALLY... studied.
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 }
#5
ok, this is the complete compatibility patch for his script. Note, i did change the name of the Window_ItemDetailView to Window_Details and changed the name of his global variable. all of these changes correspond to changes I made in his script. there are also a few attempts at aliasing methods from Scene_Item, and I changed a variable name (Whew...)

Moving on:
Patch so I can remove edits done directly to Scene_Item
Reply }
#6
Well, we learn by doing. Keep up the good work. Winking
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 }
#7
I meant that the Item detail window still does not appear... any suggestions?
Reply }
#8
So... um... Let's see if this bit of code you wrote even functions. Try THIS slight edit.

Code:
alias new_update update
  def update
    
    $currenthighlighteditem = @item_window.item
    if @itemdetail_window.active
      p "I am Working!"
      update_detail
      return
    end
    new_update
  end

The p "I am Working" is an annoying popup that is brought onto the screen if this if...end block is even working. If you don't see it, then your @itemdetail_window is not being turned on.

The 'p' (aka print) feature can help you trace things.
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 }
#9
ok, no matter which method i put
Code:
p 'I am working!'
in, i never see the popup. so... this class isnt being called... do i need to initialize this new class? like do I need to do something to Scene_Menu to call this instead of scene_item?
Reply }
#10
So, it's not this block, but the routine that you have that sets @itemdetail_window.active to true

Check that section out.

If you don't, look at Jackatrades's original. Somewhere in his script, he has something like

Code:
if Input.trigger?(Input::A)
    @itemdetail_window.active = true
  end
Which would (in essence) activate the item detail window if the Shift button was pressed.
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: 6 Guest(s)