Posts: 325
Threads: 9
Joined: Feb 2016
(09-10-2017, 11:54 PM)kyonides Wrote: It is used between two different arrays to extract specific values from both of them, but it does not alter any of them, they keep their own values because it is like a calculation not a modification, it reads both arrays and returns a new one with the end result, namely values both have in common like the same numbers or heroes.
NEATO!
I'm learning so much from this thread its crazy and I love it!
almost enough to send a pic of what I look like to Kyonides!
new logo for Yesteryear created by Lunarberry!
Posts: 4,592
Threads: 536
Joined: Dec 2009
09-11-2017, 05:32 AM
(This post was last modified: 09-11-2017, 05:34 AM by kyonides.)
array | array2
That would return all values both arrays have got except repeated values, so no 1,1,1 or Actor with id 1 and another with id 1, just one 1 or a single Actor with id 1, plus any other values they never had in common.
"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
(09-11-2017, 05:32 AM)kyonides Wrote: array | array2
That would return all values both arrays have got except repeated values, so no 1,1,1 or Actor with id 1 and another with id 1, just one 1 or a single Actor with id 1, plus any other values they never had in common.
so the | is like a divider between rooms?
new logo for Yesteryear created by Lunarberry!
Posts: 4,592
Threads: 536
Joined: Dec 2009
09-11-2017, 05:52 AM
(This post was last modified: 09-11-2017, 05:54 AM by kyonides.)
Divider? Never! It collects everything that looks different, unique, plus a single copy of any repeated value. Let's say both arrays are boxes, one is yours and other is Lunarberry's. Both keep videogames or music CD's only. Your younger sister shows up looking for all videogames and see both boxes include Pacman. She stalls and later decides to pick all games but the second Pacman videogame because she only needs one. There your younger sister would be the |.
"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
(09-11-2017, 05:52 AM)kyonides Wrote: Divider? Never! It collects everything that looks different, unique, plus a single copy of any repeated value. Let's say both arrays are boxes, one is yours and other is Lunarberry's. Both keep videogames or music CD's only. Your younger sister shows up looking for all videogames and see both boxes include Pacman. She stalls and later decides to pick all games but the second Pacman videogame because she only needs one. There your younger sister would be the |.
ok so the | is pretty much finding doubles and only choosing one of them instead of processing both?
makes more sence!
new logo for Yesteryear created by Lunarberry!
Posts: 25
Threads: 15
Joined: Aug 2016
09-11-2017, 08:07 AM
(This post was last modified: 09-11-2017, 08:11 AM by LiTTleDRAgo.)
Hmm, let's talk about ||
If in my previous post '&&' is used like a 'then', this '||' is the opposite of that.
Look at example below
Code: #==============================================================================
# ** Sprite
#------------------------------------------------------------------------------
# A sprite class for bitmap processing.
#==============================================================================
class Sprite
alias anti_dispose_error_alias dispose
def dispose
disposed? || anti_dispose_error_alias # <<<<
end
end
The code above is fixes to prevent disposed sprite to throws an error if disposed again.
Normally when Sprite is disposed twice, an error would pop up saying "Sprite was disposed.". That code is prevents that.
I believe you already know about alias so I won't touch it.
Let's look at disposed? || anti_dispose_error_alias. The method disposed? is a method in class Sprite to check if Sprite already disposed or not, the method returns true if already disposed or false if haven't.
It's just like asking the sprite : "Hey sprite, have you already disposed?"
Moving on, let's talk about '||' behavior, as you probably guessed, it's opposite of '&&'.
If '&&' will check the next sentence only if previous one are true, the '||' will check the next sentence only if previous one are false or nil!
So based on that behavior if sprite is already disposed, it will not check anti_dispose_error_alias.
false || false || false || true || false || true || ......
As you see, the program will stop reading when the condition are true.
By the way:
|| = or
disposed? || anti_dispose_error_alias
disposed? or anti_dispose_error_alias
Those two are same things.
Posts: 4,592
Threads: 536
Joined: Dec 2009
09-11-2017, 06:51 PM
(This post was last modified: 09-11-2017, 07:11 PM by kyonides.)
You forgot to explain what disposed means just in case she needed further clarification. Dispose as in the verb to dispose of something means to throw it at Ruby's garbage can so it will get rid of it once Ruby gets some spare time to do that like while leaving a menu scene and returning to the current map. You gotta make sure of disposing windows and sprites, stuff like arrays and hashes can be cleared, but you don't need to dispose them because they normally don't hold graphics. If they do like in Scene_Load and Scene_Save then you would need to make an each loop to dispose every single window they are holding; there an array holds the windows that show you your saved game files.
Alias, in case you didn't know this already, is a nickname, so alias in Ruby (I never found it in javascript) is a pseudo variable that lets you nickname methods. You could alias them if you think its current name is too large or in case you need to add new values or calculations to the method you need to change.
class Game_Actor
attr_accessor :bank_pin
alias my_initialiaze_alias initialize
def initialize(actor_id)
@bank_pin = ""
my_initialize_alias(actor_id)
end
end
There I modified Game_Actor, the class that holds Pod Pod's data, to add a bank PIN for her! I needed to add my nickname my_initialize_alias to let the game create the rest of its values as it usually does. I passed an argument because the original method initialize badly needs it.
attr_accessor is a method from Module that lets you quickly create a method named bank_pin and another one called bank_pin= that let you get and set Pod Pod's bank PIN at any time!
PIN is a number you enter in a machine to get access to your money!
"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
thank you both! this is fantastic information! I'm gonna hold off asking any more questions for awhile as I need to focus on other things and let my mind absorb all this info!
new logo for Yesteryear created by Lunarberry!
Posts: 4,592
Threads: 536
Joined: Dec 2009
Here's another curious thing about classes in Ruby, they are not static, meaning you can add new methods at will. How many methods? That depends on you only! Getter methods like those created by attr_reader belong to their own class and not the copies you make of their class.
Class Game_Actor
attr_reader :age, :height, :weight, :hunger
def max_age
100
end
end
$game_actors[50] = Game_Actor.new(50)
$game_actors[50].name = "Evil Pod Pod"
$game_actors[50].age = 0
Here comes the explanation, I created a new actor namely Evil Pod Pod, even if you ask how long Aluxes, the first hero, should ever live or need to get Evil Pod Pod's end of cycle date, they both would only live 100 hours or 100 days or 100 years because we have not determine the basic life unit we will use to set the duration of their life cycles. Why do they all have the same time limit? Because methods like max_age are class specific for they make no distinction between Aluxes or Evil Pod Pod, and they do not return a variable with a value, the maximum age, specific for the idiotic fighter or the newborn cat-droid. Variables like @age do belong to their owners, that idiot and that evil robot respectively.
$game_actors[1].age = 16
$game_actors[50].age = 0
Ask them how old they are...
p $game_actors[1].age
16
While Evil Pod Pod would reply she is not even one year old because she was born last October??
"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
01-23-2018, 10:13 PM
(This post was last modified: 01-23-2018, 10:14 PM by Siletrea.)
(01-23-2018, 09:55 PM)kyonides Wrote: Here's another curious thing about classes in Ruby, they are not static, meaning you can add new methods at will. How many methods? That depends on you only! Getter methods like those created by attr_reader belong to their own class and not the copies you make of their class.
Class Game_Actor
attr_reader :age, :height, :weight, :hunger
def max_age
100
end
end
$game_actors[50] = Game_Actor.new(50)
$game_actors[50].name = "Evil Pod Pod"
$game_actors[50].age = 0
Here comes the explanation, I created a new actor namely Evil Pod Pod, even if you ask how long Aluxes, the first hero, should ever live or need to get Evil Pod Pod's end of cycle date, they both would only live 100 hours or 100 days or 100 years because we have not determine the basic life unit we will use to set the duration of their life cycles. Why do they all have the same time limit? Because methods like max_age are class specific for they make no distinction between Aluxes or Evil Pod Pod, and they do not return a variable with a value, the maximum age, specific for the idiotic fighter or the newborn cat-droid. Variables like @age do belong to their owners, that idiot and that evil robot respectively.
$game_actors[1].age = 16
$game_actors[50].age = 0
Ask them how old they are...
p $game_actors[1].age
16
While Evil Pod Pod would reply she is not even one year old because she was born last October?? great info to know thank you very much!
lol Pod-Pod was technically "born" in 2011 as thats when she was designed! for official ingame though her birthdays not for another 595 years
new logo for Yesteryear created by Lunarberry!
|