RGSS scripting dissections and explinations
#74
Let's make the board's mockup class now!  Grinning

Code:
class Forum
 def initialize
   @name = ""
   @url = ""
   @status = "OK"
   @admins = [ ]
   @members = [ ]
   @sections = { "Announcements and Updates" => [ ] }
 end
 def name() @name end
 def status() @status end
 def url() @url end
 alias address url
 def admins() @admins end
 def members() @members end
 def sections() @sections end

 def name=(new_name) @name = new_name end
 def status=(new_status) @status = new_status end
 def url=(new_url) @url = new_url end
 alias address= url=
end

Now we're gonna create our forum...

$save_point = Forum.new
$save_point.name = "Save-Point"
$save_point.address = "https://www.save-point.org"

Mmm it looks fine so far but we do need people populating it, don't we?  Laughing

Code:
class ForumMember
  def initialize
    @name = ""
    @legend = ""
    @title = ""
    @number_of_posts = 0
    @posts = [ ]
    @thanks_given = 0
    @last_visit = Time.at(0)
    @hobbies = [ ]
    @status = "Average User"
  end
  attr_accessor :name, :legend, :title, :number_of_posts, :thanks_given
  attr_accessor :last_visit, :status
  attr_reader :posts, :hobbies
end

So let's go make new forum members! Shocked

@Siletrea = ForumMember.new
@Siletrea.name = "Siletrea"
@Siletrea.legend = "Making a game about a forgotten robot"
@Siletrea.title = "YesterYear developer"

@Siletrea.hobbies = ["Play Ace Attorney games too many hours a day", "Reading Dune series of books?", "Dream on making robots", "Love Spyro just because", "3D animation", "Collect stray cats"]

@Kyonides = ForumMember.new
@Kyonides.name = "Kyonides"
@Kyonides.legend = "A lazy scripter that needs to get some sleep"
@Kyonides.title = "Dark Scripter"
@Kyonides.hobbies = ["Making scripts", "Compiling stuff", "Use Linux distros", "Pick on Siletrea because it's fun!", "Laughing at Spyro", "Calling PodPod Evil PodPöd", "Ignore evil bounter hunters", "Sadly talking to an Argentinian that prefers to use floats and the to_i method instead of multiplying by m and later dividing by 100"]

Adding new members to the forum

$save_point.members << @Siletrea << @Kyonides

But there is no point in registering members only so let's add some admins as well!

Code:
class ForumAdmin < ForumMember
 def initialize
   super
   @status = "Administrator"
 end
end

@DerVVulfman = AdminMember.new
@DerVVulfman.name = "DerVVulfman"
@DerVVulfman.legend = "Looking as furry and ugly as Dilgear"
@DerVVulfman.title = "Administrator"
@DerVVulfman.hobbies = ["Eating ramen just because", "Skipping lunch almost every single day", "Talk about Doctor Who like a parrot", "Collect stray cats"]

@Kirito = AdminMember.new
@Kirito.name = "Kirito"
@Kirito.legend = "I randomly post stuff on the board unless I broke something!"
@Kirito.title = "Technical Administrator"
@Kirito.hobbies = ["Making chat bots that only know how to bother innocent sharks but lick anybody else's face instead"]

Let's add those new members to the forum's list of admins.

$save_point.admins << @DerVVulfman << @Kirito

Updating the forum status...

$save_point.status = "Avatars are broken, thank Kirito for it :P"

Think that super or super() or super(argument1, argument2) and etc. are like a Siletrea that runs to her mother crying a lot because some guy named Kyonides laughed at Spyro the dragon. It's like asking your mother to do you a favor (no arguments needed here) or updating her about what has happened if super gets some arguments like. i.e.

Code:
class SiletreasMom < Person
  def being_picked_on(report)
    @report = report
    cry_out_loud_at_the_person_who_is_bothering_her_daughter
  end
end

class Siletrea < Person
  def being_picked_on(report)
    super(report)
  end
end

@siletrea = Siletrea.new
report = "Kyonides is a meanie! He dared to laugh at Spyro the dragon!"
@siletrea.being_picked_on(report)

At the same time it's also what wulfo said, a way that prevents you from typing the same stuff all over again because you got stuff from your mother like, err, hair and eye color, height, a couple of her old books, dunno what else...

@instance variable... Why don't we define the term instance first? Let's check what the search box tells us about it.

Quote:in·stance
/ˈinstəns/
noun
noun: instance; plural noun: instances
Case 1
an example or single occurrence of something.
"a serious instance of corruption"
synonyms:
example, exemplar, occasion, occurrence, case;
illustration
"an instance of racism"

Case 2
a particular case.
"in this instance it mattered little"

Sarcasm + Confused It's not extremely simple so let's go rephrase it a little bit...

Case 1: Something I can use to teach something to Siletrea or anybody else or anything I can use as a warning in case they are about to make a terrible mistake or somebody that is practically flawless and other people should follow that very same person or a case of a corrupt politican that steals money or pollutes a river while other local politicians haven't done such terrible things before, etc. As a summary it is linked to number one 1 alias picking a single thing. Shocked

Case 2: Being unique or specific to a person or some stuff, where specific stands for something that describes that person or thing but not another. A good example would be me picking on you while nobody else like wulfo or lani or kirito does the same here. Laughing

So what's an instance variable?

A unique or specific trait or feature that is included in a class and will be sent to a specific copy of that class but not to another unless you pass the same value on purpose.

Code:
class Female
  def initialize
    @name = "Some girly girl's name"
  end
  def name() @name end
  def name=(new_name) @name = new_name end
end

@siletrea = Female.new
@siletrea.name = "Siletrea"

@another_girl = Female.new
@another_girl.name = "Siletrea"

In that case both girls would call themselves Siletrea but only because I did it on purpose. Laughing + Tongue sticking out

@another_girl.name = "Puma"

Now the other girl is your cat Puma! Shocked

Well, that's possible only because I didn't define Female as a human exclusive class so female cats are also included by default. So if we compare both names we can quickly notice that their names are unique, different, specific, not a simple photocopy. Grinning

Warning! Shocked

If I go pay a visit to another script, both @siletrea and @another_girl would mean nothing to it so it will tell you they can't be found anywhere. Instance @variables might disappear if they aren't stuck to anything that won't be forgotten by the game any time soon. One "solution" would be using the dollar sign $, which in Siletrea's own dialect it might be called the bunny ear. Making a global variable $girls = [@siletrea, @another_girl] will store them till the game is closed by the player. A better method could be using $game_temp or $game_system or $game_party or even $game_actors to store them via a method (the def guys we keep typing here), just pick a good name for that new method. One could also create a new module like:

Code:
module Girls
  def Girls.add(*girls) @add += girls end
  @add = [ ]
end

Girls.add(@siletrea, @another_girl)
"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-14-2018, 10:02 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,112 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,227 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: 17 Guest(s)