[XP] Inheritance - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Games Development (https://www.save-point.org/forum-4.html) +--- Forum: Code Support (https://www.save-point.org/forum-20.html) +--- Thread: [XP] Inheritance (/thread-3251.html) Pages:
1
2
|
[XP] Inheritance - xuroth - 03-02-2011 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... RE: [XP] Inheritance - DerVVulfman - 03-02-2011 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 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. RE: [XP] Inheritance - xuroth - 03-03-2011 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 Code: alias new_update update EDIT2: (but at least I didnt get method or syntax errors!) RE: [XP] Inheritance - DerVVulfman - 03-04-2011 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. RE: [XP] Inheritance - xuroth - 03-08-2011 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 RE: [XP] Inheritance - DerVVulfman - 03-08-2011 Well, we learn by doing. Keep up the good work. RE: [XP] Inheritance - xuroth - 03-08-2011 I meant that the Item detail window still does not appear... any suggestions? RE: [XP] Inheritance - DerVVulfman - 03-08-2011 So... um... Let's see if this bit of code you wrote even functions. Try THIS slight edit. Code: alias new_update update 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. RE: [XP] Inheritance - xuroth - 03-08-2011 ok, no matter which method i put Code: p 'I am working!' RE: [XP] Inheritance - DerVVulfman - 03-08-2011 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) |