how to insert automatically a bunch of data with "for" into an array?

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
183
Reaction score
37
First Language
Italian
Primarily Uses
RMMV
wordList = []

for ( i=0; i<16; i++){
actorName = $gameActors.actor(i).name.toUpperCase();
wordList.push(actorName(i));
}

this does not work, someone have a solution? i'm beginner in javascript for now, still learning.

cannot read property " name " of null.
 

deykuzor

Korean Guy Screaming in Italian American
Member
Joined
Sep 7, 2017
Messages
23
Reaction score
5
First Language
English
Primarily Uses
RMMV
My javascript is also weak but if you're getting a "cannot read" message, it's probably because whatever it's trying to find the property in is not actually an object (yet). Javascript has no private variables so like, you can technically read anything if you extend it properly..

Looks like you're attempting to push a list of party member names to an array. I think, not sure, but the problem may be related to not having an actual object made before trying to access the name property in $gameactors
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
725
Reaction score
582
First Language
French
Primarily Uses
Your syntax is all over the place.
You define actorName as a string that will contain an actor's name and in the line below you call it as a function with actorName(i). You just need to push the currently defined actorName inside the loop.

That's not the error you're getting though. It sounds like you've tried to access the name of an actor that doesn't exist. Look at your database, you'll see that actor ids start at 1 and not 0. That's why you're getting the crash. You're trying to get $gameActors.actor(0) and it doesn't exist. Start your loop from actor 1 after fixing the first mistake I pointed out and it should work.
 

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
183
Reaction score
37
First Language
Italian
Primarily Uses
RMMV
Ast, do you mean this?

for ( i=1; i<17; i++){
wordList.push($gameActors.actor(i).name().toUpperCase());
}

and what do you mean syntax all over the place?
 

deykuzor

Korean Guy Screaming in Italian American
Member
Joined
Sep 7, 2017
Messages
23
Reaction score
5
First Language
English
Primarily Uses
RMMV
Yeah sorry, I totally blanked. You don't need this:

wordList.push(actorName(i))

It should be

wordList.push(actorName);

cos as Astfgl66 pointed out, you already set the actor at that pointer in the array to actorName. And yeah, like we both pointed out, there was nothing at index 0, so

for ( i=0; i<16; i++)

should have been (i=1;i<16;i++)

I would recommend looking at how operators, arrays, pointers, and properties within RMMVs current classes work.

As someone who is also learning and needed Astfgl66's insight to remind me, programming is a lot of remembering what the building blocks you have can do, and then using them correctly.
 

deykuzor

Korean Guy Screaming in Italian American
Member
Joined
Sep 7, 2017
Messages
23
Reaction score
5
First Language
English
Primarily Uses
RMMV
Ast, do you mean this?

for ( i=1; i<17; i++){
wordList.push($gameActors.actor(i).name().toUpperCase());
}

and what do you mean syntax all over the place?

Sorry for the double post, but I think what he meant was you're calling actorName like it was a function by putting the (i) there when you already set actorName as a string object. Look at my second post.
 

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
183
Reaction score
37
First Language
Italian
Primarily Uses
RMMV
btw as it is works fine, isn't better this format? more compact?
 

deykuzor

Korean Guy Screaming in Italian American
Member
Joined
Sep 7, 2017
Messages
23
Reaction score
5
First Language
English
Primarily Uses
RMMV
If it works, then it works but compactness can impede clarity. Code clarity enables you or others to quickly read it and change/adjust it. It's a good practice to be clear during development and then upon release, try and then compact the code. You can write an easily read version and comment out a more compact version to use later if it helps.
 

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
183
Reaction score
37
First Language
Italian
Primarily Uses
RMMV
yeah but this little script is meant to be used as a personal tweak and not for public scope, i got the info btw i knew that thanks anyway
 

Latest Threads

Latest Posts

Latest Profile Posts

Is it necroposting if I ask for more info in my own months old thread? All the information in the thread is relevant
JRPG TextBox HTML - Part 2:
So I'm resuming work on the Shadowstar Trilogy. I've decided that it will take place between the end of G4 and the start of G5, and two of the Lost Rulers will be Twilight Sparkle and Sunset Shimmer (who is the moon princess in my AU).
Been working on some sprites, My favorite out of all of them is this guy, his name is Moss:

Forum statistics

Threads
108,958
Messages
1,040,871
Members
141,418
Latest member
Emileewitt
Top