Game Crashing Issue

I'm not sure how to go about this, so I'd try to go in order:

I have a piece of coding as a common event as follows:

(Note: Missing, console logs before each show balloon icon and after)

I intend to have a varying number of events (should vary from 0 to 8) call this common event once during parallel processing:

(Note: Substituted the code into the map event for testing reasons. Normally each event just calls the common event and turns on a self switch [C in this case])

One event (currently an action event) changes the self switch of the other events that need to execute the common event coding (The self switches [B in this case] turn on successfully judging on my console logs).

So, going over again:
i) Event A (action event) runs and turns on other events' self switch B.
ii) While Event A is running, the other events' parallel process (via self switch B ) triggers and executes code to make them jump in surprise.
iii) The other events disable this page by turning on self switch C.
iv) The other events remain idle until Event A reaches another point in their coding.

The game crashes under various conditions:

1) As is:


When more than 1 event runs the common event code, it crashes before the "After Jump" console.log (Cause: Movement Route?).

2) With Set Movement Route Wait disabled:


When more than 1 event runs the common event code, it crashes after a console log at the end of the coding (after the conditional branch).

A) Game does not crash when 1 event with the parallel process exists on the map.
B ) When I test it with more than 1 such event, it crashes.
C) I tested it with two such events, one whose trigger for the common event coding was possible, the other not
(I changed the self switch (B ) required for the parallel process to work. So 1 event needed B, the other C). It still crashes.

I noticed it's probably risky using the same variable for the randomness, so I changed each use to a different variable. Still crashed. Odd thing is that in scenario (2) the code seemingly reaches the end of that common event. The next page of the map events is just an empty action event page that requires self switch C to be on.

Can parallel events not execute the same movement route command? Or show balloon command?
It's troublesome to replicate because the playtest screen becomes a static-like black and white image that causes my display drive to crash (and soon recover). (It also somehow permanently messed up the display of one chrome tab :/ Refreshing it produced the same distorted image, but that's going off-topic lol)

Edit: The display drive crashing problem only happened when I tried to take screenshots. Otherwise, I've so far replicated the crash without affecting my pc.
sounds like a timing problem, and those are usually one hell of a problem to sort out.
I can't help you directly, but here is some info that might help you out:

set move route is a command that is not executed directly but sets a move route for independent execution.

Basically that means that the new move route becomes an additional process to be handled in the main game loop which already handles all parallel processes - those commands are NOT executed as the part of the original parallel process.
There is also the limit that only one move route per event is allowed, any additional set move route command on the same event will overwrite the existing move route even if that is not yet completed.

Somehow I think that the references are messed up - you might want to place a link to the script that is used for changing the self-switches, and a screenshot of the event that activates the events you showed us, so that we can see if that is where the interference comes from.
Error in eval is event script. I only see 1 line console.log's for your event scripts.
What has a line 2, as indicated by your error console?
I suspect there is an error in an event script not shown to us.
@Andar ; If I can't make the events jump surprised at the same time, I can make them do it sequentially instead. I'd test that in a while. I'm curious how the problem still occurred when the trigger for another event was practically disabled by changing it though. Anyways, code that activates the other events below. Also includes self-switch control (From the bottom to top, just look for "Self B On" sticking out on the right.

@mogwai ; Sorry. Not sure if I follow correctly. By line 2 are you referring to those with undefined: 2?

◆Common Event:Eval: Player Grid Loc
◆Control Variables:#0011 Current Map ID = Map ID
◆Control Variables:#0024..0027 = 0
◆Control Variables:#0257..0259 = 0
◆Text:None, Window, Bottom
: :Evil Laugh
◆Comment:Prepare Influenced Mushis Array
◆Script:corrupted = [];
: :$gameVariables.setValue(256,corrupted);
◆Comment:Evaluate Arrays (Look for nearby Mushis)
◆Script:var NumMushi = []; var xMushi = []; var yMushi = []; var loop = 0;
: :for (var e = 0; e < $dataMap.events.length; e++) {
: : if ($dataMap.events[e] === null) { continue }
: : if (~$dataMap.events[e].note.indexOf("<Mushi>")) {
: : NumMushi.push($dataMap.events[e].id);
: : xMushi.push($dataMap.events[e].x); yMushi.push($dataMap.events[e].y);
: : loop++;
: : }
: :}
: :$gameVariables.setValue(25, NumMushi);
: :$gameVariables.setValue(26, xMushi); $gameVariables.setValue(27, yMushi);
: :$gameVariables.setValue(24, loop);
◆Comment:Shift out elements of Arrays (During a loop)
◆Loop
◆Script:var num = 0; var x = 0; var y = 0;
: :num = $gameVariables.value(25).shift();
: :$gameVariables.setValue(257,num);
: :x = $gameVariables.value(26).shift();
: :$gameVariables.setValue(258,x);
: :y = $gameVariables.value(27).shift();
: :$gameVariables.setValue(259,y);
: :
: :loop = $gameVariables.value(24);
: :loop--;
: :$gameVariables.setValue(24, loop);
◆Common Event:Eval: Mushi Grid Loc
◆If:Player Grid Loc X = Mushi Loc X
◆If:Player Grid Loc Y = Mushi Loc Y
◆Comment:Player (& Grim) at same location of Mushi. Record Mushi into Array.
◆Script:var influenced = $gameVariables.value(257);
: :var transfer = $gameVariables.value(256);
: :transfer.push(influenced);
: :$gameVariables.setValue(256, transfer);
◆Comment:Player (& Grim) at same location of Mushi. Influence Mushi.
◆Script:key = [$gameVariables.value(11), $gameVariables.value(257), "B"]
: :$gameSelfSwitches.setValue(key, true);
◆Script:console.log($gameVariables.value(257) + ": Self B On");
◆Wait:2 frames
◆
:End
◆
:End
◆If:Loop Number = 0
◆Break Loop
◆
:End
◆
:Repeat Above
◆Script:console.log("Influenced Mushis: " + $gameVariables.value(256));
◆Text:None, Window, Bottom
: :Behold!
◆Control Switches:#0249 Grim Influence [Flag] = ON
◆Wait:120 frames
◆Text:None, Window, Bottom
: :Mushis converted!!
simple question:
why not command the event directly when you identify it? Why setting a self-switch to a parallel process at all?

Both set move route and show balloon icon are targeted commands, and the code above could set them by script instead of setting a self-switch by script, and that would remove a lot of code and many parallel processes from that map.
And the script commands to do that by script and variable should be in the list of script equivalents of event commands...
Sometimes line 2 means there is an error on line one, but it kept trying to go.
If all you have is 1 line console.log() perhaps one of them is misspelled.

I was assuming there might be a bigger 2 or more line event script to focus on.

Does your max on the game variables run up to 256? I assume it already does, but that can make an undefined if it doesn't.

I see one thing maybe... yMushi = [];
$gameVariables.setValue(27, yMushi);

Can variables take arrays?
simple question:
why not command the event directly when you identify it? Why setting a self-switch to a parallel process at all?

Lol, I thought of that while I was typing up this thread. I actually can't recall my reasoning for deciding to go about it a parallel process way. Maybe it had to do with timing and wanting to make them jump at the same time. Anyways, from this:

Edit: Oh, it's displaying the whole sheet :S



I don't know how to script movement route commands.
Sometimes line 2 means there is an error on line one, but it kept trying to go.
If all you have is 1 line console.log() perhaps one of them is misspelled.

I was assuming there might be a bigger 2 or more line event script to focus on.

Does your max on the game variables run up to 256? I assume it already does, but that can make an undefined if it doesn't.

I see one thing maybe... yMushi = [];
$gameVariables.setValue(27, yMushi);

Can variables take arrays?

My max game variables is 720 atm, lol. And oh. So (still a bit confused) are you saying the undefined:2 could indicate what you said about an error on line one or misspelling? Umm. Yea, there are common events that execute 2+ console logs in one script command.
Do you have a plugin to make game variables have arrays?

I think you meant to
$gameVariables.setValue(25, NumMushi[0]);
$gameVariables.setValue(26, xMushi[0]); $gameVariables.setValue(27, yMushi[0]);

and then when done with the event ID at 0, you might mushi.shift(); on those or something to go to the next. I'm not sure how you'll go about processing all those event Id's unless there is a plugin doing $gameVariables
Do you have a plugin to make game variables have arrays?

I think you meant to
$gameVariables.setValue(25, NumMushi[0]);
$gameVariables.setValue(26, xMushi[0]); $gameVariables.setValue(27, yMushi[0]);

and then when done with the event ID at 0, you might mushi.shift(); on those or something to go to the next. I'm not sure how you'll go about processing all those event Id's unless there is a plugin doing $gameVariables

I don't think I do. I tested the code partially though. After that array section, I outputed the value of that variable and it was like: 42,13,5,20.
Then I can shift out each value during the loop and got, individually, 42, then 13, then 5, then 20.
The way $gameVariables is set up and setValue coded, variables can take array assignments without needing a plugin to let you do so.
I learned something today.
Screen Shot 2017-02-24 at 1.11.05 PM.png


Cool.
But what does key do when you set $gameSwitches(key) with it? Is that a plugin?
Screen Shot 2017-02-24 at 1.16.23 PM.png
$gameSwitches doesn't work quite the same way. They're both arrays, so you can't pass an array as their ID either way, but the way $gameSwitches.value is coded it's forced to return a boolean. There's absolutely nothing stopping you from storing a string, an array or whatever in it, but all you're going to get when you check its value is true or false.
@mogwai
◆Script:key = [$gameVariables.value(11), $gameVariables.value(257), "B"]
: :$gameSelfSwitches.setValue(key, true);

key is an array variable that represents [map ID, event ID, self switch]. I hope I answered you properly. Edit: Okay, maybe you knew that already. Sorry.

and @ Andar oh I think I remembered. Originally, before I thought of making the events do some sort of animation, I wanted each event to announce a certain value that I use for something else later. So that, in editing this scenario throughout my game, I'd just edit what value each event can call. Then I thought of including the animation and guess I got caught up with that when I tried to split apart the stages of eventing.

Edit: I think the script equivalent to move route (jump) would be:
$gameMap.event(n).jump(0,0);
?

Looking under Game_CharacterBase in rpg_objects. I'd test this out soon.
I have a suspicion. When you set game variable 257 to game variable 25 shift();

Screen Shot 2017-02-24 at 1.49.35 PM.png


It actually becomes 0 which can't be shift or push.
Screen Shot 2017-02-24 at 1.50.47 PM.png


I think you already know how to fix this.
EDIT:
Nevermind. I see you are using all shift like this. I thought this one was a snafu.
PHP:
var num = $gameVariables.value(25);
num.shift(); // then shift num
$gameVariables.setValue(257,num);

No worries. I've used shift and pop in the same way at times.

You taught me about $gameSelfSwitches too. I only get so analytical because I can only recreate snippets of all of that and I am learning RMMV too.
Well I've edited the code till it works to a flexible point that I'd like. As pointed out above, I've moved the surprise reaction to inside the loop section. The problem where it crashed for multiple events occurred after one loop. The problem for this was that the start of the loop section involved shifting elements out of an array, but the ending of the loop section (random variable) manipulated (oversight on my part) one of those arrays - so I just changed the random variable to another. I've also incorporated yanfly's move route core. Just to get the events to turn towards another event and command marked events to show a balloon animation.

Spoiler: Working Code
◆Comment:=========================================================================
: :Grim Influence Map Event (Initialization)
: :-------------------------------------------------------------------------
◆Control Variables:#0011 Current Map ID = Map ID
◆Control Variables:#0024..0027 = 0
◆Control Variables:#0257..0259 = 0
◆Control Variables:#0269 Num of Victims = 0
◆Control Variables:#0270 Grim ID = 0
◆Comment:Prepare Influenced Mushis Array
◆Script:corrupted = [];
: :$gameVariables.setValue(256,corrupted);
◆Comment:--------------------------------------------------------------------------
: :Evaluate Player Grid Location & Grim ID
◆Common Event:Eval: Player Grid Loc
◆Script:for (var e = 0; e < $dataMap.events.length; e++) {
: : if ($dataMap.events[e] === null) { continue }
: : if (~$dataMap.events[e].note.indexOf("<Grim>")) {
: : console.log('Grim Detected!');
: : $gameVariables.setValue(270, $dataMap.events[e].id);
: : }
: :}
◆Comment:Evaluate Arrays (Look for nearby Mushis)
◆Script:var NumMushi = []; var xMushi = []; var yMushi = []; var loop = 0;
: :for (var e = 0; e < $dataMap.events.length; e++) {
: : if ($dataMap.events[e] === null) { continue }
: : if (~$dataMap.events[e].note.indexOf("<Mushi>")) {
: : NumMushi.push($dataMap.events[e].id);
: : xMushi.push($dataMap.events[e].x); yMushi.push($dataMap.events[e].y);
: : loop++;
: : }
: :}
: :$gameVariables.setValue(25, NumMushi);
: :$gameVariables.setValue(26, xMushi); $gameVariables.setValue(27, yMushi);
: :$gameVariables.setValue(24, loop);
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Script:console.log("[CE] <<<<<<< Grim Influenced Entered >>>>>>> ");
: :console.log("Grim ID: "+$gameVariables.value(270)+" | Nearby Mushi IDs: "+$gameVariables.value(25)+" | Time: "+$gameVariables.value(7));
: ://console.log("- - - - - - - | Movements: "+$gameVariables.value(49)+" | - - - - - - -");
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Text:None, Window, Bottom
: :Evil Laugh
◆Comment:========================================================================
: :Grim Influence Map Event (Shift out elements of Arrays (During a loop))
: :------------------------------------------------------------------------
◆Loop
◆Script:var num = 0; var x = 0; var y = 0;
: :num = $gameVariables.value(25).shift();
: :$gameVariables.setValue(257,num);
: :x = $gameVariables.value(26).shift();
: :$gameVariables.setValue(258,x);
: :y = $gameVariables.value(27).shift();
: :$gameVariables.setValue(259,y);
: :
: :loop = $gameVariables.value(24);
: :loop--;
: :$gameVariables.setValue(24, loop);
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Script:console.log("| Loops Remain: "+$gameVariables.value(24) +" | (Do Mushi Reaction)" );
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Common Event:Eval: Mushi Grid Loc
◆If:Player Grid Loc X = Mushi Loc X
◆If:Player Grid Loc Y = Mushi Loc Y
◆Comment:Player (& Grim) at same location of Mushi. Record Mushi into Array.
◆Script:var influenced = $gameVariables.value(257);
: :var transfer = $gameVariables.value(256);
: :transfer.push(influenced);
: :$gameVariables.setValue(256, transfer);
◆Comment:Player (& Grim) at same location of Mushi. Influence Mushi.
◆Script:$gameMap.event($gameVariables.value(257)).turnTowardEvent($gameVariables.value(270));
: :$gameMap.event($gameVariables.value(257)).jump(0,0);
◆Wait:4 frames
◆Control Variables:#0221 -- Misc -- = Random 1..2
◆If:-- Misc -- = 1
◆Script:$gameMap.event($gameVariables.value(257)).requestBalloon(1);
◆
:Else
◆Script:$gameMap.event($gameVariables.value(257)).requestBalloon(2);
◆
:End
◆Script:key = [$gameVariables.value(11), $gameVariables.value(257), "B"]
: :$gameSelfSwitches.setValue(key, true);
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Script:console.log("Event "+$gameVariables.value(257) + ": Reaction Done & Self B On");
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Wait:4 frames
◆
:End
◆
:End
◆If:Loop Number = 0
◆Break Loop
◆
:End
◆
:Repeat Above
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Script:console.log("Influenced Mushi IDs: " + $gameVariables.value(256));
◆Comment:~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
◆Text:None, Window, Bottom
: :Behold!
◆Control Switches:#0249 Grim Influence [Flag] = ON
◆Wait:120 frames
◆Text:None, Window, Bottom
: :Mushis converted!!
Code:
num = $gameVariables.value(25).shift();
these ^ will still make a type error
Code:
$gameVariables.value(25).shift() === 0

Screen%20Shot%202017-02-25%20at%2010.22.53%20AM.png


You need to make these instances of shift
Code:
num = $gameVariables.value(25);
num.shift();

shift shifts an array, but shift returns 0.
@mogwai Huh. I haven't gotten any errors though. Is it a warning or game crashing error?
It will only make a type error if you use array functions on it like shift, pop, push, or unshift.

But just so you know every variable you use shift that way on is 0. So if you if you try to num[0] it will return undefined.

The only reason it's not making any errors is that you wrote around it and now that code is vestigial.

The only way using shift will work that way is if you make a hackish patch like this, which wouldn't be very safe.
PHP:
Array.prototype.oldShift = Array.prototype.shift;
Array.prototype.shift = function(){
   this.oldShift.call(this, arguments);
   // normally return 0;
   return this; // unsafe
}

Original thread: https://forums.rpgmakerweb.com/threads/game-crashing-issue.75275/