Hi there,
Is there a script call that I can use to change the value of multiple variables at once? I know I can do it individually by using the "Control variable" command. But I was hoping if I could do the same thing more efficiently using a single script call. Thanks.
Uuh... what's your plan with multiple variables at once?
Don't get me wrong, scripts and plugins that help people to create stuff on their own instead of copying pre-built systems are a very great thing.
Correct me if I'm wrong, in RPGMV/MZ, the control-command should still allow you to choose a batch-range of variable-IDs as target for repeatedly executing the very same action with all of them.
If the opportunity was missed to order those variables in a sequence of incremental IDs to properly use this function, the mistake here might be bad planning.
RPG2000/2003 lack of an open re-programmable engine and have stuff like allowing you to e.g. specify a target-variable based on one or multiple pointers, but if stuff on that level is what you need for something in MV/MZ, some red flags are raising that you might wanna create something that is considered too complex and unstable to be ever handled by the event-interpreter and should be programmed in JS entirely instead.
~炬燵あ
Control Variables -> Range won't work for me, as I am trying to set different values for different variables.
For example, let's say, I want the value of variable 2,3, 5, and 8 is 5, 3, 9 and 7. And I want to do all that with a single scriptcall to keep things tidy.
Thanks. That really helps. And while I have you, is there any similar script call to do the same with self-switches? I wanted to change the self-switch A of events 4,5,6,7,8,9 of Map 16. I usually do it with this script:
var key = [mapId, eventId, A-D]
$gameSelfSwitches.setValue(key, true);
Is there any better way to change the value of multiple self-switch at once?
use the same syntax for key as the example for data several posts above.
this will not work with functions, but it will work for arrays whether they are const or var.
you would still have to call the setvalue function in a loop for every kay.
I'm not sure if pressing four unrelated-seeming different values into four different variables with only one line of code can be considered "kept tidy". But okay, as long as it's only you who has to find their way through it if something has to be replaced or adjusted later again.
~炬燵あ
Well, in one of the events of my game, I have to enter eight variables between each dialogue. I could have used a common event, but I also have to change the value of some variables as well. Which created a big mess. That's why I'm looking for this types of sulution.
I'd just like to point out that doing this by using setValue inside a for loop is definitely better than modifying _data directly, since the latter won't call onChange, and might cause some weird issues with events using the wrong pages or plugins that respond to variables not noticing the change.
I guess you could just call onChange yourself when you're done, but it's probably safer to just stick to using setValue.