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
713
Reaction score
564
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
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Super stoked i just finished my first town in my project, by finished i mean i can always add more decorative aesthetics and the NPCs don't talk yet but the mapping is complete and all the important chess pieces are present!
My brain: Hey, I have an idea how to make the transition to the main story quest in The Wastes more natural!
Me: Good!
My brain: You need to remake the hotel you start out in, it's not realistic enough.
Me: Ok... This was unexpected, but I can do it.
My brain: Now make each hotel floor 5 times as large to match the main part. Oh, you also need to make a bunch of new npcs to fill in the space on these maps.
Me: Crap.
Should be able to release Haxe MV/MZ next weekend.
It look that somehow MZ tracks are messed up (for example battle4 is obviously a theme, castle2 is a ship, ship1 is a scene and so on..). Maybe they just named them after with some ambiguity.
is there a script call that return how much turn has passed in battle?

Forum statistics

Threads
100,607
Messages
977,777
Members
132,219
Latest member
aboyhazard
Top