@caethyril or @Rlyeh or Anyone else who knows JS. I have been trying to understand exactly what is happening with the script outlined above and what I incorporated in my test event. I have been looking things up for JS and trying to balance that with how I think it is being used in MZ specifically. But there are some things that just aren't clicking.
Would anyone be willing to break this script down with an explanation of what is happening in plain language? If so, I would be eternally grateful!
Once again, here is the screenshot of the script part of my test event:
So here is what I think I understand. However flawed it might be.
choices = [ ];
Is creating an empty array and choices is what MZ uses for the Show Choices command?
$gameParty.members().forEach(m => choices.push(m.name()));
Is using .forEach to cycle through all the party members and pushing (adding) the names to the choices array. m is referencing the members and m.name is referencing the member name? Not sure why an => is needed here.
choices.push("Nevermind");
Is pushing (adding) "Nevermind" to the choices array in the last position so that will be an option outside of the party member names.
$gameMessage.setChoices(choices, 0, choices.length-1);
I think is setting a variable Choices to the choices array, not sure what 0 is doing unless it is referencing the first position in the array, and then something about the last position in the array so something about "Nevermind". Maybe this is saying the variable Choices is set everything in the array from position 0 to the last position?
$gameMessage.setChoiceBackground(1);
Is setting the background for the choices message display which you would normally set through the Show Choices command in the event.
$gameMessage.setChoicePositionType(1);
Is setting the position for the choices message display which you would normally set through the Show Choices command in the event.
$gameMessage.setChoiceCallback(n => {
I read what a callback does, but I'm not really clear on what this is doing and the n is throwing me off too. I read that n could be a reference to a line break, but I don't think that is what it is doing here. Is n what is being selected as a choice?
$gameVariables.setValue(106, n!=choices.length-1?n:-1);
This is setting the variable designated as 106, but I am having trouble interpreting this too. I read that != means NOT equal so I think that is saying n is NOT equal to "Nevermind" because choices.length-1 is the value of the last position in the array which is "Nevermind". I read that : can mean size. But I also read that ?: can be a conditional statement like if then. Is this essentially setting the value of variable 106 to a number depending on the number of your party members like 0, 1, 2, 3, 4, -1?
});
I think this is just closing the callback.
this.setWaitMode('message');
I read about wait in JS and I think this is using the WaitMode option in MZ. I'm not sure what the 'message' part is all about unless that is just referring back to waiting for a choices selection to be made.
So as you can see, maybe I understand a little bit of what is going on or maybe not. And a lot is unclear. I am starting to work through an online JS class to start learning from the very beginning but that is a slow process.
Again, if anyone is willing to help me understand what is actually happening in this script, in plain language, that would be awesome. I really appreciate folks' time and patience with new users.
Thanks!
Would anyone be willing to break this script down with an explanation of what is happening in plain language? If so, I would be eternally grateful!
Once again, here is the screenshot of the script part of my test event:
So here is what I think I understand. However flawed it might be.
choices = [ ];
Is creating an empty array and choices is what MZ uses for the Show Choices command?
$gameParty.members().forEach(m => choices.push(m.name()));
Is using .forEach to cycle through all the party members and pushing (adding) the names to the choices array. m is referencing the members and m.name is referencing the member name? Not sure why an => is needed here.
choices.push("Nevermind");
Is pushing (adding) "Nevermind" to the choices array in the last position so that will be an option outside of the party member names.
$gameMessage.setChoices(choices, 0, choices.length-1);
I think is setting a variable Choices to the choices array, not sure what 0 is doing unless it is referencing the first position in the array, and then something about the last position in the array so something about "Nevermind". Maybe this is saying the variable Choices is set everything in the array from position 0 to the last position?
$gameMessage.setChoiceBackground(1);
Is setting the background for the choices message display which you would normally set through the Show Choices command in the event.
$gameMessage.setChoicePositionType(1);
Is setting the position for the choices message display which you would normally set through the Show Choices command in the event.
$gameMessage.setChoiceCallback(n => {
I read what a callback does, but I'm not really clear on what this is doing and the n is throwing me off too. I read that n could be a reference to a line break, but I don't think that is what it is doing here. Is n what is being selected as a choice?
$gameVariables.setValue(106, n!=choices.length-1?n:-1);
This is setting the variable designated as 106, but I am having trouble interpreting this too. I read that != means NOT equal so I think that is saying n is NOT equal to "Nevermind" because choices.length-1 is the value of the last position in the array which is "Nevermind". I read that : can mean size. But I also read that ?: can be a conditional statement like if then. Is this essentially setting the value of variable 106 to a number depending on the number of your party members like 0, 1, 2, 3, 4, -1?
});
I think this is just closing the callback.
this.setWaitMode('message');
I read about wait in JS and I think this is using the WaitMode option in MZ. I'm not sure what the 'message' part is all about unless that is just referring back to waiting for a choices selection to be made.
So as you can see, maybe I understand a little bit of what is going on or maybe not. And a lot is unclear. I am starting to work through an online JS class to start learning from the very beginning but that is a slow process.
Again, if anyone is willing to help me understand what is actually happening in this script, in plain language, that would be awesome. I really appreciate folks' time and patience with new users.
Thanks!