RGSS scripting dissections and explinations
#85
Code:
class SomeIdioticSampleClass
  def a_moronic_method
    @any_instance_variable = any_value
    @just_another_instance_variable * 2
  end
  def just_another_instance_variable
    @just_another_instance_variable
  end
  def just_another_instance_variable=(new_value)
    @just_another_instance_variable = new_value
  end
end

In that excessively stupid example, I made it look idiotic on purpose, you can see two kinds of methods or "defs". The first method processes stuff like a computer would do it in the 50's or 60's while the second method is just a getter (method).

Getter or something that lets you get some instance variable, is like a store you don't own where you are allowed to purchase food or autoparts or tools but you can't sell them anything back.

A setter (method) like the third def above would be comparable to a store like DerVVulfman's pawn shop where you can sell them stuff if they find it worth buying it from you, a total stranger that rarely pay them a visit. (Well, you're Canadian, you're not supposed to walk around Maryland every single day of the year. Laughing + Tongue sticking out ) The stranger would be any other class script, either you, MetalRenard, Kirito, LunarBerry, Nyakuya, etc. Anybody would be allowed to set any specific price to their product and try to sell it there. (Just skip the haggling part of the business here. Laughing )

An accessor in Ruby, a getter-setter combo, would be like Wulfo's shop but you would not only try to sell them stuff but also look for any interesting item like a guitar, a sword or a bow you might wanna buy for your personal collection.

SIDENOTES

As a sidenote I gotta admit that talking about super method is a BAD idea if a newbie is involved for super is one of Ruby's strangest exceptions to its rules. Let's say it's the only method that under certain circumstances might require to get a pair of () parentheses while no other method in Ruby actually needs them. (A lot of internal history of Ruby development is also involved here...)

a wolf once Wrote:Now that's what it is like if you have a super statement with parameters. It MUST be duplicating a method with an equal number of parameters.

Well, usually he would be right, BUT there is an exception in RGSS 1 and later versions (XP and later versions of the maker). If the last parameter of a child class's method is an array described as *array, then it might only look like it had the same number of arguments in both the child and parent class in the class scripts themselves (their defs). Sadly a call to those methods, using Class.method(argument1, argument2, argument3, argument4, etcera), might apparently have many more arguments or parameters or passed down values than those found in the defs where they were defined initially. WHY? Because the last *array parameter is like a large net waiting for some extra fish to catch than the amount the government would normally allow a single boat to catch in the sea. In the Class.method case etcera would be that special net's first victim.

In default scripts like Window_Base and so on you won't find such eccentricities or definitely crazy stuff at all, but I warn you it might happen a little bit more often in custom scripts.

By the way, super without () parentheses is not an innocent baby after all. It actually passes from 0 up to 17 arguments or passed down values to its parent class. Why zero as first possibility or option? Go ask Ruby's creator! Laughing The developers' team preferred to let you pass "nothing" as well in case the parent class did not need any parameter at all.

If you create your custom window class like I did here:

Code:
class MySharkyWindow < Window_Base
  def initialize(x, y, width, height)
    super
    self.z = 1000
    self.bitmap = Bitmap.new(width - 32, height - 32)
    self.bitmap.draw_text(0, 0, width - 32, 24, "I'm a shark with a laser gun!")
  end
end

You're passing down all four parameters to Window_Base, it's parent class. Yeah, Ruby let's you be quite lazy and skip the urge to specify what parameters the child class needs to pass down to its parent class. super is a perfect complement for lazy people! Laughing
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by kyonides - 11-20-2018, 05:38 AM

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



Users browsing this thread: 14 Guest(s)