Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#10
Well, VVulf said a module was like a collection of classes (like collecting stamps or cards), but that's not completely true. It's just one way to use them. There's another one that's sometimes encourage to use depending on your coding style. They also call modules mixins (think about a mixer at a construction site) because they allow you to mix different methods found in a class with the module's methods.

Class A has 10 methods.
Module M has 10 methods of its own.
You mix them like this...

class A
include M
end

From that point on Class A has 20 methods! What's better is that even a new class like C can get module M's 10 methods as well! The curious thing is that class B has no need for them so it keeps its original, err, let's say it had 8 methods and never added anything else so it only has those 8 methods.

Some methods are called properties or attributes. That would mean they can be used to change or describe that class, let's say Class Siletrea has a property like age that is equal to 20 but you need to update it soon to display 21 instead

class Siletrea
def initialize
@year_of_birth = 1996
@age = 20
end
def age() @age end
def age=(new_age) @age = new_age end
end

$girl = Siletrea.new
# In year 1996 she was born.
$girl.age #=> 20 (years)
Few days later she celebrates her birthday
$girl.age += 1 #=> 21 (years)
Now she's one year older than before, obviously.
+= there is the same as $girl.age = $girl.age + 1 meaning we just added a year to her age by means of a handy shortcut. All mathematical operators can be used the same way, I'm talking about + for sums, - for substractions, / for divisions, * for multiplications and % for modulo (what didn't fill a box but it still has some used spaces that you can't ignore, it could be anything like soda or flavored water bottles or even numbers)

$girl.age (def age() @age end in the class's list of available methods) is a getter, you fetch things but do nothing else later on.
$girl.age = 1 would be a setter, you set the value, meaning you define what it should be equal to, meaning you CAN change it at any time if deemed necessary. (If you don't need anybody to change a property or attribute, then don't define anything like def age=(new_age) @age = new_age end )

R,G,B,A? shoudent it be R,G,B,L as in Red Green Blue Luminescence/Light whats the A mean?

A stands for Alpha or transparency or luminous stuff, etc. 255 is completely visible, 120 looks like a ghost and 0 well, you can't tell where did it go because you can't see it.

DerVVulfman the local werewolf Wrote:[ ] The Brackets.
Oh this is used more for arrays, regardless of how the array is used. OR, it is used to identify a KEY in a hash array. Long story, not yet for beginniers.... it is another story.
I DO disagree with him, I was a total noob when I learned how hashes actually worked, then I posted my first script namely something like Sprite_CurrentTime or Window_CurrentTime using it as the clock you can find in a corner of your laptop or desktop monitor.

@hash = {} # Empty
@hash = { 1 => [] } # The hash is not empty but I made a new one that now includes 1 as key and an empty Array as its contents.
What's a hash key? An identifier, meaning a name on a list named @hash that you opened to check if on Monday 1st you have collected any fruits in a basket, but you realized you haven't got any so far.
@hash[1] #=> []
Yeah, a few hours later it's still empty, you haven't found any kiwis, yet!
@hash[1] << Kiwi.new
What? you found a new kiwi!
@hash[1] #=> [<Kiwi:0x0934f3>]
Yes, you stored a kiwi there on day one. Those numbers are like a barcode to later find it on a PC or cash register when you scan it with a sensor with a red laser. (Ruby needs it but you don't so leave it as it is, don't even try to change it.)
Every time you find another kiwi the array will grow (your box gets filled slowly).
@hash[1] += [Kiwi.new, Kiwi.new, Kiwi.new]
You add 3 new kiwis you recently picked up.
@hash[1] #=> [<Kiwi:0x0934f3>, <Kiwi:0x09e4f3>, <Kiwi:0x0d34f3>, <Kiwi:0x093413>]
Now you've got 4 kiwis already labeled so you may noticed if a relative has sold them out as expected or not.
The day is over and day one's box won't get any more kiwis because you left it at the store already. The next day you pick a new box.
@hash[2] = [] #=> []
Obviously it's empty! So on Tuesday 2nd you go out looking for more kiwis or probably oranges. (Repeat the same steps you'll get the idea.)
So 1 or 2 are keys, they might represent anything, here they are equal to a day of the month, but they could be stuff like 'Angela'

@families = { 'Angela' => [Kid1, Kid2], 'Siletrea' => [], 'Mandy' => [Baby1] }

There 'Angela', a woman's name, refers to her very own kids, since we don't know anything about 'Siletrea' bearing any kids at all, her array is empty, and 'Mandy' has a newborn. I could have used surnames instead if I felt like it.

! is a negation, !Siletrea.good_girl would mean somebody thinks you're a bad girl XD it's like writing Siletrea.good_girl == false, == in a row are a Comparison because they do compare your goodness to false if anybody thinks so. You want it to tell you're good? Then what about this?

if Siletrea.good_girl
Siletrea.smile
else
Siletrea.cry
end

If somebody tells you that you're good then you smile at them. Otherwise you'd cry out loud telling them how unfair they were by telling you you can't be good.
"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 - 09-07-2017, 05:15 AM

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



Users browsing this thread: