More Array Functions

I have been reading a lot about arrays lately which were mainly from Stack Overflow and Ruby docs, however I seem not to be able to produce what I wanted in a script in RGSS3. Mainly the following:

1. How can I access ANY elements of the array?

Let's say I am checking an array of numbers, how can I check if anything from the array may contain what I am checking?

ex:

foods = ["Bacon", "CheeseBurger", "Ham", "Hotdog"]from this array named foods, I wanted to check if the foods array contains "Bacon". Sure enough, I can say it like:

if foods.first == "Bacon"however, I wanted a way to check everything from the array. More like checking what's inside the array that I wanted to check.

Another reason why I want this is if I am checking a bunch of array elements. Say for example I made an array of Equipment or Item Ids, and I wanted to check if that equipment or item array has "Potion" in it, how can I implement this?

2. How can I shortcut adding arrays?

I have a plan of making bunch of array elements, may it be 10s or 20's. However, you'll probably ends up making bunch of script codes to call elements of an array.

My question is this: Is there a way to add an array from 1 element to 30 elements?

for example I have an array:

bunch_of_arrays = [[1], [2], [3]]now, instead of adding [4], [5], [6] inside the array, is there a more easier way to add 4 to 190?

Thanks in advance for those who would answer.
Try using hash.

It has:

#has_key?(key)

#has_value?(value)
I wanted a way to check everything from the array. More like checking what's inside the array that I wanted to check.
Use the include? method for an array

now, instead of adding [4], [5], [6] inside the array, is there a more easier way to add 4 to 190?
Use a loop.
Try to read RMVXA helpfile

It helps me a lot since I started to learn scripting

Open up help file --> RGSS3 Reference Manual --> Standard Library --> Built-in Classes --> Object --> Array
If I do have a value called:

x = 9

and I have an array First_Array with values: 9, 8, 7, 6, 5...

how would I use the include? method? I have another method that checks for the value, so I am lost how to.

Code:
first_array = [9, 8, 7, 6, 5]if self.actor_has_this_item?(first_array) # this is where the problem is. I wanted to make# sure that if the actor has the item id (which is anything from the first array, whether #it be 9, 8, 7,6 or 5...
unless ur using a custom inventory script, items are saved to the party not per actor...

anyway:

Code:
first_array.each do |item_id|  if $game_party.has_item?(item_id)  endend
PS: I'm not sure if has_item? was the correct call... the idea is that this will check if the party has any of those items from the array
Let me give a quick example

array = [1,2,3,4,5]array.include?(9) # This will return falsearray.include?(3) # This will return true array.all? { | x | x < 3 } # This will return falsearray.any? { | x | x < 3 } # This will return trueCopy pasted from helpfile. Since I'm not sure of my english skill

all? {|item| ... }

Returns true if all items are true. If any item is false, immediately returns FALSE.
When using a block, evaluates the block for each item and returns TRUE if all outcomes are true. If the block returns FALSE at anytime, immediately returns FALSE.

any? {|item| ... }
Returns FALSE if all items are false. If any item is true, immediately returns TRUE.

When using a block, evaluates the block for each item and returns FALSE if all outcomes are false. If the block returns TRUE at any time, immediately returns TRUE.
@theodoric - Wow, that sums it up. Thanks!
anyway, all of these are explained on the help file anyways... you can really learn a lot by just reading those then looking at the default scripts for actual examples
I was able to do what I wanted. Thanks for all your help. Mods can close this now.

Original thread: https://forums.rpgmakerweb.com/threads/more-array-functions.23993/