(11-11-2018, 09:28 PM)DerVVulfman Wrote: Full understanding of what wings are, type of wings... joint coordinate with each other????
OMG! I think Siletrea read the Frank Herbert novel 'Children of Dune' as she basically creating her own version of the Bene Gesserit summation of the 'The Union of Opposites'.
And yes, when you make a Child class, you can essentially 'whiteout' a method copied over from the Parent class. But you do that by making your own version of that method. If the parent class has a 'get_silly' method, the child must too have a 'get_silly' method.
Okay, the Superclass thing...
Like I just said, your Child class must have the same methods as the Parent class, even if the Child rewrites the Parent's methods. But that doesn't give you much flexibility. That would only ensure that your child is a literal XEROX of the parent without any new features.
The whole thing about the Superclass is that you can create a new method in the Child class and quickly copy the stuff from the old method into it. Basically, the use of the super() statement is a shortcut so you don't have to manually enter every single item from the parent's version. It does that work for you.
If the parent class has a method called 'punch_freddy' and it looks like this:
Code:def punch_freddy
@target = @freddy
@target.hp -= 20
@target.damage = 20
@target.flash = white
@target.falls = true
end
You can use the super() statement in your child class to make a new 'punch_freddy' method like this:
Code:def punch_freddy
super()
@target.woozy = true
@target.screams = true
end
This saves some space in your code, so your child class doesn't have to rewrite everything like this:
Code:def punch_freddy
@target = @freddy
@target.hp -= 20
@target.damage = 20
@target.flash = white
@target.falls = true
@target.woozy = true
@target.screams = true
end
Looks like the new code with the super() statement only has three lines including the super() statement. Certainly seems better than remaking the method with seven lines, right?
And let's face it, this is a small example. Some methods you might be inheriting are HUMONGOUS! WHO WANTS TO REWRITE A 30-LINE METHOD WHEN THROWING A super() IN ITS PLACE CAN BE DONE?
YES, def means define. It is a statement that defines the start of a method. You use the 'class' statement to define the start of a class, and a 'module' statement to define the start of a module. You use the def statement so frequently because you make a lot of methods when writing code.
Again, it's heiarchy: A module can hold multiple classes, and classes can hold multiple methods... all a tree of sorts. Or a shrub if the guy writing the code is a total mess. ^_^
Now why use the ampersand (@) to define a variable rather than the dollar sign ($)... First, let's talk about what we call them.
The variables with the $ symbol are called 'global' values. They work throughout the whole system. Not just one code, but could be referenced throughout your entire SCRIPT LIBRARY!!!! WOOO! POWER. But it has drawbacks. It's a memory hog, using more resources than instance variables (next on the agenda). Also, it's riskier. If one script uses a $global variable of a particular name and another script uses a $global variable of the same name, they could wipe each other out!
The variables with the @ symbol are called 'instance' variables. They are defined to work specifically within their class. And because they are class specific, you can have two classes with instance variables of the same name. So if two different classes have a @my_name variable, they each can have different values set to each of them. One won't overwrite the other. Well, not without effort on the scripter's part. And they use less memory resources.
So while the $global variable has more reach, the @instance variable allows better coding.
ok firstly I have no idea what a XEROX is...and secondly...the superclass thing...its a way of...adding new things into a prexisting system without having to go back to the old script right?
the @ symbol still confuses me but I understand the $ alot more now! thanks!
new logo for Yesteryear created by Lunarberry!