Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#93
Topic: @

Code:
class CD
  attr_accessor :name
  def initialize
    @name = ""
  end
end

Code:
class DVD
  attr_accessor :name
  def initialize
    @name = ""
  end
end

As you can see above, both classes have an instance variable @ named @name, what the at symbol @ does for name is to let the classes get an attribute or property called name, BUT they have different names!

Siletrea Wrote:How could it ever be different if both of them are called ""?

That's true for now, but once you change one name, let's say CD's name, DVD's name won't be the same as CD's. Why? O_o? Well, that's because they have a similar but not identical attribute called name. (Identical means you won't find a single difference ever, no matter how many times you might check out both names.)

Do you remember wulfo said something about Xerox that you didn't understand? He later mention it was a photocopy machine, a device to make copies of any text, number, picture, etc. Well, Ruby and RGSS do have their own photocopy machine code to make it happen at any time you need to make a new copy of CD and DVD classes. Why? O_o? Because there's supposed to be tons of CD's and DVD's in the world! (Even if their actual contents suck like Scary movie or Twilight series.)

Instance would mean A Copy here. A single object called name attached to CD or DVD like an attachment to a post or an email.

Every time you call CD.new or DVD.new or Pet.new or Shop.new you're telling Ruby and RGSS that you want to get a Copy of CD or DVD or Pet or Shop with unique, "quite different", attributes or names or properties or contents. So every @variable will hold its own set of values, either a unique basket [] or {}, or some number like 1 or 1250 or a name "Puma meowing all night long Videoclip". Even if they all might start with the same value like "", there won't be a limit or restriction on what it could be later on. @name might start as "" but they change to "My First CD" if you change it inside CD class or from any other class or script with @cd.name = "My CD has got a new name!".

attr_accessor lets you change it from outside CD or DVD class with this @cd.name = "My CD has got a new name!"

But attr_reader would only let you get alias "retrieve" the name from CD's or DVD's @name like this @cd.name
No equal = sign, no "text", nothing on its right hand side.

The period or dot or point . is a connection or link between @cd and name to tell Ruby you want to get CD's name not any DVD's name.
"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 - 12-29-2018, 08:47 AM

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



Users browsing this thread: