RGSS scripting dissections and explinations
#91
Ooooh. Gotta make a note here. Thankies, Kyo.

Within the "Scene_PetConvention" class, we get to see both @instance and local values, the siletrea value, the @puma value and the dervvulfman value. But they're not just values. kyonides made OBJECTS!!!!

An object is a value that acts as a usable copy of another class, assuming data is within.

Code:
siletrea = Person.new
    siletrea.name = "Siletrea"
    siletrea.age = 22 # Guessing here...

Remember what I said. Local values are even CHEAPER than @instance values.... they only work within the method whereas the @instance values can work throughout the class.

And here, the siletrea local value is really the siletrea local OBJECT... only usable within the method it's created. And again, it's an object... assuming the structure of the 'Person' class (the 2nd class in his example). The Person class has three values: Name, Age and an array of pets. So when he made a siletrea object, he had to fill in the values for the object. He could have put in more methods that could be run... but ... later.

Slowly study this.

OH, and remember how I said in the post ...
Quote:There's a bit more too it than just this. We need to do stuff that lets that whole '$game_siletrea' thingie to work. But once we do, this is how you can make @instance variables from one class work within other classes.

This creation of an object is how we make those $game_system and $game_temp objects. Laughing So in my previous example where I suggested reading data from $game_siletrea.... we do need to make an object first.

Winking Yes, that means you can make $global objects too!!!

But just glance through this, and again.... Talk about the classes, super class, parent, child. I know you want to take things slowly. Not to jump into things too fast. We'll get back to this eventually.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#92
hmm I'll have to reread all of this when I'm more awake but things are starting to make more sence

I like the sound of super()'s! my spelling is generally terrible so if I can take a "easy" approach and avoid a metric butt-ton of typing that sounds fantastic to me!

and @'s can be used within its own class...and have other classes modify it?...but can't be used in every class under the same name/funtion?
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#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 }
#94
This would just be a simple script event call, but anyone know how to make it work?
Don't think I've truly looked at every script in well over a decade...
Code:
dir = pi * arctan2(Player.y - Npc.y, Npc.x - Player.x) * (180 / pi) / 180;
x+=cos(dir)*2;
y+=-sin(dir)*2;
Reply }
#95
In general, this thread is to help explain the basics of scripting as you might have gathered. It puts everything in layman terms, as simple as possible. Not necessarily meant for advanced mathemetics.

BUT, not to dweell over that. Most of your formula is accurate, with only a few exceptions for Ruby itself. The constant value of pi is actually just Math::PI.... all capitals. That's how it is in Ruby. And the arctan statement is part of the Math module, that being the statement of Math.atan2(y, x). It's actually in RPGMaker's help file, though you do have to dig around.

I believe, this may suffice?
Code:
dir = Math::PI * Math.atan2(Player.y - Npc.y, Npc.x - Player.x) * (180 / PI) / 180;
x+=cos(dir)*2;
y+=-sin(dir)*2;

EDIT: Edit made to PI value as noted by kyonides
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#96
I'm aware of the functions, however the function is meant to actually move the Player or Event and that is the part I'm struggling with.
Not so much the math behind it :p
Reply }
#97
Confused Err, it's Math::PI unless you include Math module in any custom class or module....
"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 }
#98
Oh no! Math! My worst subject! And now food has been forcefully incorporated! Even if it’s spelt wrong I will forever think pie is tasty!
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }


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



Users browsing this thread: 3 Guest(s)