Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#72
(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!
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by Siletrea - 11-13-2018, 08:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Help iwth script (RGSS Player crash) Whisper 3 7,674 06-17-2017, 05:03 PM
Last Post: Whisper
  How can I use the cmd of "require" in rgss superegp 2 5,383 11-03-2015, 06:16 AM
Last Post: kyonides
   Scripting in VX vs VX Ace Miharu 5 8,207 02-21-2015, 10:10 AM
Last Post: Taylor
   Combat animations via scripting; How? ZeroSum 2 4,572 09-20-2013, 06:58 PM
Last Post: ZeroSum
Question  RGSS stoped to work Chaos17 5 6,930 02-14-2013, 05:13 PM
Last Post: DerVVulfman
   Ruby, RGSS & General Code Discussion Kain Nobel 6 9,916 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   [Request] Tut. for RGSS Eldur 9 10,612 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 3,863 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Scripting I think spazfire 7 8,984 04-12-2010, 03:21 AM
Last Post: DerVVulfman
   Beginner Scripting Tuts? KDawg08 1 3,685 03-31-2010, 11:03 PM
Last Post: Hsia_Nu



Users browsing this thread: