Status
Not open for further replies.

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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.
 
Last edited by a moderator:

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Try using hash.

It has:

#has_key?(key)

#has_value?(value)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,922
First Language
English
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,344
Reaction score
11,115
First Language
Indonesian
Primarily Uses
N/A
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
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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...
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,032
First Language
Tagalog
Primarily Uses
RMVXA
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
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,344
Reaction score
11,115
First Language
Indonesian
Primarily Uses
N/A
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.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
@theodoric - Wow, that sums it up. Thanks!
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,032
First Language
Tagalog
Primarily Uses
RMVXA
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
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I was able to do what I wanted. Thanks for all your help. Mods can close this now.
 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Design Aesthetic Question Time. For the Main Menu:

Primary and Subclasses


Side By Side:

SbSClassesStyle.png

Or Stacked:

StackedClassesStyle.png
World building was one of the main reasons i got in to game dev, but geeez, it eats up the time... This is a WIP from today before i call it a night.. maybe 80% finished.
maps.png
Dial_000_f002_show.jpg
Wohoo, its finished. It took some time but slowly I get used to this retro 90s anime style.
Now I just have to finish the other 37 frames. for the first dialogue... oh lord, what have I done :LZSlol:
(and if you are confused: yes, I place various eastereggs about other great cyberpunk games/videos/books that I like in my game ;) )
Has anyone watched the movie "Tiny Toons: How I Spent My Summer Vacation"? It is a cartoon and it is freaking hilarious. We watched that movie so many times when our kids were growing up. Thankfully it has a lot of adult humor to keep the adults entertained that the kids don't really get.
Here's some more weapon icons for the Wastes I've finished recently. Some are mine, some are icons that @Ninjakillzu originally made (the AK variants, the Thompson, the Glock, the M16 variants), but edited by me with permission.
1686428693206.png1686428742838.png

Forum statistics

Threads
131,778
Messages
1,223,308
Members
173,563
Latest member
yiuro
Top