so, I thought that I had a good grasp on aliasing, but then I started thinking about it a little more and confused myself...
example: a basic HUD alias
class Scene_Map
alias mainHUD_main main
alias mainHUD_update update
def main
@window_HUD = Window_HUDMain.new
mainHUD_main
@window_HUD.dispose
end
def update
@window_HUD.update
mainHUD_update
end
end
so, what is the deal with the aliased method placement? It usually works out for me in the long run, because I can just switch them around if anything is acting up... but what exactly is going on here? Is it that @window_HUD has to be defined before the main method is called so it can be disposed? But if thats the case, why is update above mainHUD_update?
Because in the "main" method, the process is getting caught in a loop, so any code below the normal method will not execute until the loop is broken, ie. the scene ending.
ex.
def main
blah blah
loop { update things }
dispose stuff
end
alias whatever_main main
def main
aliased blah blah (this is before the normal method is called, which catches it in a loop)
whatever_main (calls normal method, starting loop)
more aliased blah blah (does not execute until whatever_main's loop has broken.
end
ah, I think I got it.. @window_HUD.update is in #update which gets called in the main loop, so @window_HUD needs to be defined before #main is executed.
Yeah, pretty much anytime you ever alias the "main" method in a scene, you have to instantize any objects before calling the normal method. Anything after it will not execute until the scene ends. You can alias the initialize method of scenes if want to avoid the confusion. Although it may not be defined in your script, "new" is a inherited method of the Class class (I didn't mis-type that, by the way). Its called anytime a new instance is created.
Quote from: ForeverZer0 on December 29, 2010, 03:20:51 pm
Yeah, pretty much anytime you ever alias the "main" method in a scene, you have to instantize any objects before calling the normal method. Anything after it will not execute until the scene ends. You can alias the initialize method of scenes if want to avoid the confusion. Although it may not be defined in your script, "new" is a inherited method of the Class class (I didn't mis-type that, by the way). Its called anytime a new instance is created.
But what is the difference between the Class class and the Object class, then (lol, completely off-topic :D)?
Cya :urgh:!
Object is the superclass of Class. The only thing above object is Kernel. The hiearchy is basically something like this:
/ - Class
Kernel --> Object --<
\ - Module
As you can see, this is what they mean by "everything is an object" when talking about Ruby. Almost every last little thing is an ancestor of the Object class.
To answer your question, class is really just a basic struct to define a couple (I think it is only 2 or 3) common functions for instances. The Module class is different, it has quite a few functions, but is used for static objects that do not have instances.
The Class class is a class the describes the structure of a class. Basically when you create a new class, what actually happens is that a new instance of class Class is created into which all information about your class is stored.
Quote from: Blizzard on December 29, 2010, 05:07:15 pm
The Class class is a class the describes the structure of a class. Basically when you create a new class, what actually happens is that a new instance of class Class is created into which all information about your class is stored.
brilliant!
just to bring another non sequitur into the mix, what isn't an object in Ruby? Only things that come to mind are blocks? methods?
No, Method is a class as well. If you want to learn more about Ruby, google some documentation on. It actually opened up a whole new level of coding for me. Try searching for Ruby 1.8 Core CHM file (what RMXP uses), or the much better 1.9, but you will find a lot that RMXP cannot use, but can be written in yourself if needed.
hey thanks, I've actually been reading/scripting a lot more with ruby lately than RGSS. I've been cracking open the pick axe, pocket reference and also WHY's excellent reads.
my last post was kind of on an impulse, and so I did a little research... Someone on stackoverflow says that methods aren't objects (http://stackoverflow.com/questions/2602340/methods-in-ruby-objects-or-not) but then this guy (http://www.mentby.com/david-a-black/are-methods-objects.html) explains the whole sitch a little better
I suggest watching this excellent talk on the ruby object model: http://scotland-on-rails.s3.amazonaws.com/2A04_DaveThomas-SOR.mp4
I learned a bunch from it ^_^
*hugs*
Methods are objects. They belong to the Method class. Classes are objects.
http://www.ruby-doc.org/core/classes/Method.html
You gotta love how they abbreviate it as meth.
Quote from: Zeriab on December 30, 2010, 04:58:37 am
I suggest watching this excellent talk on the ruby object model: http://scotland-on-rails.s3.amazonaws.com/2A04_DaveThomas-SOR.mp4
I learned a bunch from it ^_^
*hugs*
Wow, such an awesome video! I'm gonna level you up for this :D!
Cya :urgh:!
Quote from: ForeverZer0 on December 30, 2010, 08:51:10 am
Methods are objects. They belong to the Method class. Classes are objects.
http://www.ruby-doc.org/core/classes/Method.html
hahaha damn... that's me just overthinking. I've looked at that page so many times now, and it just never dawned on me in the course of this convo :shy:
Quote from: ForeverZer0 on December 30, 2010, 08:51:10 am
Methods are objects. They belong to the Method class. Classes are objects.
http://www.ruby-doc.org/core/classes/Method.html
But Object is a class? Wow, Ruby really is a complicated language :D.
Cya :urgh:!
EDIT: All right, I lost it somewhere. So, if in this script:
A is a constant, that is an instance of the Object class, what has happened with the Class class...? *confused*
Cya :urgh:!
Every language is complicated in structure. You shouldn't bother trying to understand things like this right now. It will come to you when you're more experienced.
Yes, the Object class is actually recursive. Object is the super class of Class. Class describes Object itself and the actual definition of Object is an instance of Class. The definition of Class is also an instance of Class. A bit confusing, I know. That's why I said that you shouldn't bother with this stuff now and concentrate on just learning how to use everything.