Hello
@Bokeh. Since you intended to use what you call the first script you should know of certain issues it will have once you start testing it.
Thank you both
@ATT_Turan and
@BenSD!
That first script should do just fine for what I need, but I appreciate the alternatives in case I get snagged in implementation.
The idea is correct but the code itself is wrong.
Code:
var mentors[4, 5, 6, 7, 8, 9, 10];
This will give you a syntax error. This is probably just an oversight. If not corrected the code will still run but you'll get weird values and a script call error if you press F8 during playtesting.
This will delete all elements in the
mentors array starting from
index. For example, if
index === 3, i.e. 7 then
mentors will become equal to
[4, 5, 6]. If
index === 0, i.e. 4 then
mentors will become empty and, assuming 4 isn't the last variable value, subsequent values will give you zero (0) which will in turn give you errors when you try to match zero with actor IDs.
Assuming the syntax error had been correctly written and everything else kept as is, the code from that script call will run without errors but you'll notice the following:
Spoiler: Playtesting Behavior
- If 5 isn't the last variable it will always be followed by 4.
- If 5 is the first variable or 4 is either the first or second variable you will always get at least one 0.
- If you get anything else you'll notice the values you get are ALWAYS strictly decreasing i.e. X > Y > Z. As mentioned above, this is due to
mentors.splice(index);.
- The code was meant for three (3) rather than four (4) randomly selected elements from the
mentors array.
If the above behaviors are acceptable to you then you just need to correct the array declaration code
var mentors[4, 5, 6, 7, 8, 9, 10]; in the first script call.
If you want to properly accomplish what you intended in your first post,
i.e. random selection without replacement of 4 items out of a pool of 7, then you should use instead the code below in your script call:
Spoiler: Code
JavaScript:
var cv = [21, 22, 23, 24]; // replace these
var mentors = [4, 5, 6, 7, 8, 9, 10];
var index = Math.randomInt(mentors.length);
for (var i = 0; i < cv.length; i++) {
$gameVariables.setValue(cv[i], mentors[index]);
if (i < cv.length - 1) {
mentors.splice(index, 1);
index = Math.randomInt(mentors.length);
}
}
The above code is mostly copy and paste. Just replace 21, 22, 23 and 24 within the first line
cv = [21, 22, 23, 24]; with the IDs of your control variables containing the actor IDs of the
four (4) non-priority actor mentors from 4 to 10.