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.
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
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.
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?
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.
btw as it is works fine, isn't better this format? more compact?
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.
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