12-31-2021, 10:19 PM
(This post was last modified: 01-13-2022, 06:10 AM by kyonides.
Edit Reason: Added Script Calls
)
FixedArray
The Array With a Fixed Size
for XP VX & ACE
Have you ever wanted to keep a Ruby Array at a certain size?
Was it a pain you know where to prevent it from ever increasing its size or length?
Now you should not worry about that anymore!
Even so you can still clear its contents at any given time.
The Scriptlet
Code:
# * FixedArray
# 2022-01-11
# Have you ever wanted to keep a Ruby Array at a certain size?
# Was it a pain you know where to prevent it from ever increasing
# its size or length?
# Now you should not worry about that anymore!
# Even so you can still clear its contents at any given time.
# Examples:
# ary = FixedArray.new(3)
# returns: []
# ary = FixedArray.new(3, :a, :b, :c, :d)
# returns: [:a, :b, :c]
class FixedArray < Array
def initialize(total, *args)
@maxsize = total > 0 ? total : 0
concat args.take(@maxsize)
end
def push(elem) size == @maxsize ? self : super(elem) end
def <<(elem) size == @maxsize ? self : super(elem) end
def unshift(elem) size == @maxsize ? self : super(elem) end
def +(ary) dup.concat ary.take(@maxsize - size) end
alias :>> :unshift
attr_accessor :maxsize
end
Script Calls
You may use p or print or puts or msgbox or msgbox_p script calls depending on your debugging needs and RM version.
Actually >> is an alias of the unshift method.
Code:
array = FixedArray.new(3)
# returns: []
p array.size
# returns: 0
p array.maxsize
# returns: 3
array << :b << :c
# returns: [:b, :c]
array >> :a
# returns: [:a, :b, :c]
array = FixedArray.new(3, :a, :b, :c, :d)
# returns: [:a, :b, :c]
p array.size
# returns: 3
p array.maxsize
# returns: 3
Terms & Conditions
You may include my nickname if you want.
It's free as in beer and speech!
"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
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