Posts: 11,279
Threads: 651
Joined: May 2009
12-28-2018, 06:36 AM
(This post was last modified: 12-28-2018, 06:40 AM by DerVVulfman.)
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. So in my previous example where I suggested reading data from $game_siletrea.... we do need to make an object first.
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...)
Above are clickable links
Posts: 325
Threads: 9
Joined: Feb 2016
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?
new logo for Yesteryear created by Lunarberry!
Posts: 4,647
Threads: 554
Joined: Dec 2009
12-29-2018, 08:47 AM
(This post was last modified: 12-29-2018, 08:51 AM by kyonides.)
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.
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!
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
Posts: 30
Threads: 3
Joined: Jul 2018
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;
Posts: 11,279
Threads: 651
Joined: May 2009
03-18-2019, 03:18 AM
(This post was last modified: 03-18-2019, 03:51 AM by DerVVulfman.)
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...)
Above are clickable links
Posts: 30
Threads: 3
Joined: Jul 2018
03-18-2019, 03:25 AM
(This post was last modified: 03-18-2019, 03:26 AM by Son_Rukiri.)
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
Posts: 4,647
Threads: 554
Joined: Dec 2009
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.
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!
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
Posts: 325
Threads: 9
Joined: Feb 2016
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!
new logo for Yesteryear created by Lunarberry!
|