Dynamically get id of items

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
I have a for loop that pushes the ids of the items in the array into a new array, however Ruby is different from JavaScript and I can't seem to figure out how to accomplish this, here's how i did it in ruby:

Code:
for items_array.each do |i|
     new_array.push($data_items[i].id)
end
what is the equivalent in MV?
 

Llareian

Jack of All Trades, Master of None
Veteran
Joined
Jan 26, 2017
Messages
604
Reaction score
1,424
First Language
English
Primarily Uses
RMMV
I know JavaScript but not Ruby, so I'm having trouble reading what the function you've placed here is actually doing. It seems to be creating new_array by calling from the database, but I'm not sure what items_array is or where i comes from. Can you clarify what you need the function to do?

EDIT: To clarify some of my confusion, in MV's JavaScript,
Code:
$dataItems[i].id
returns i. So to me (without knowing Ruby) it looks like you're taking an array of item ids and making that same array again, but by filtering it through the database for some reason. Also, there are TONS of array functions you can use to pull useful information from an array of actual item objects, so I really need to know what you're trying to accomplish and what you're starting with.
 
Last edited:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
I believe the equivalent for what you have is a for...in loop, in JavaScript for...in loops are not recommended for arrays (they are useful for objects though).
Code:
//Here is a JavaScript version using a normal for loop
//Assuming itemArray and newArray are already defined variables
for (var i = 0; i < itemArray.length; i++) {
    newArray.push($dataItems[i].id);
}
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
@Llareian @Sarlecc Thank you both I'm pretty dumb for some reason I thought $dataItems.id wouldn't work when in fact it does.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

The second draft of my script is almost done, and I don't think I'm going to write a third draft. I'll make changes to dialogue here and there, but I'm happy with the series of events the way they are.
How you feel about font and dialogue box changing for every main character while the minor cast and regular npc get their own styles? Too much?
Just found an obviously custom effect (i.e. edited by me) in my resources>sounds folder called "rip jaw off". Dear Lord what is wrong with me as a person that at some point I needed a sound *specifically* for THAT??
(...rhetorical question.)
so like with the whole 'familiarity breeds contempt thingy', how are you supposed to tell if your title screen/battle music gets really tedious after a few dozen plays or if you're just personally hella sick of it?

Forum statistics

Threads
107,523
Messages
1,030,242
Members
139,648
Latest member
Heis
Top