What is "Game_Event.list"? ( I get an error cannot find 'list' of undefined )

Hello there, 


I've been getting an error: Cannot read property 'list' of undefined SOMETIMES inexplicably when I'm clicking on events and they are supposed to activate. It would happen <5% of the time, so I put on a temporary fix that seems to be stopping it, just put "Game_Event.list = 0" when a scene starts so that it's defined, as in the console when I would check it's value it was indeed undefined.


Does anyone know what Game_Event.list does or is?


EDIT: Even if I define Game_Event.list with some value, it's still happening. I've attached a screenshot of what the console says. 


The scripts I'm using: 


Skip Title Screen


Bind Pictures to Map


TDDP_Preload Manager


Web Audio Cache


YEP_CoreEngine


A Custom Input Settings Plugin


YEP_MessageCore


And then what's probably causing it: A custom run and walk script with a custom mouse cursor, and an edit to the rpg maker default script of how events are run in where you can click on tall characters to activate them instead of just 1 tile big characters. 


I'm going to do more testing tomorrow to try to squash the bug, but any help again is greatly appreciated.


EDIT2: What I'm generally understanding is that somehow "Game_Event" is undefined, perhaps it's even for a split second? If I could just do a simple "if Game_Event != undefined { } else { }" statement I feel like that would squash the bug...or at least patch it up.


cannot read property of list undefined error screenshot.png
Game_Event.list is a method that returns the list of commands from the current page of the event. If you get the error "Cannot find 'list' of undefined" on it, it means that the script can't find the current page of the event.


How many pages do your event have?


It's probably a script error somewhere, though.
EDIT3: After looking it all over, it obviously seems to have something to do with the position of the player and the position of the npc. The way I wrote the code below is not working too well....might be my use of "II" or something in the code.


EDIT2: Here is a video. I've now been wracking my brains out as to how to fix this. I think I may have to commission a javascripter to check it out...










I've tried a couple checks in Game_Event.prototype.update including checking "if (!$gamePlayer.isMoving())" and "if (!this.isMoving)" (the event isn't moving or the player isn't moving or both) and nothing works so far.


EDIT: What I know now, after doing some studying of the console with console.log(this); when the event is supposed to start, is that rpg maker mv creates a new Game_Event object every time an event is triggered on the map? I should just be able to solve this then with some kind of "if Game_Event == undefined" etc......


Alright so here's where I think the coding problem is...


Basically, I needed a way in where I could have the user click on an event to trigger it so I wrote the following code...


Some variables: 


MouseXGrid - a global value telling us where the mouse is tile-wise on the grid horizontally.


MouseYGrid - a global value telling us where the mouse is tile-wise on the grid veritcally.


Maybe what I could do is just somehow do like... "this != undefined" or something?


//Check if player is beside event
var alias_AstraCat_customEventUpdateForChecks = Game_Event.prototype.update;
//If an event is clicked and the player is adjecent to it, start that event
Game_Event.prototype.update = function() {
alias_AstraCat_customEventUpdateForChecks.call(this);

//if mouse hovering over event and event is small ('small' note is on event page)

if (String($dataMap.events[this.eventId()].note) == 'small') {
if ((this._x == MouseXGrid && this._y == MouseYGrid) ||
(this._x == MouseXGrid && this._y == MouseYGrid))
{
//if player clicks
if (TouchInput.isTriggered()) {
//if player is adjecent to event and event is small
if (($gamePlayer._x+1 == this._x && $gamePlayer._y == this._y) ||
($gamePlayer._x-1 == this._x && $gamePlayer._y == this._y) ||
($gamePlayer._x == this._x && $gamePlayer._y-1 == this._y) ||
($gamePlayer._x == this._x && $gamePlayer._y+1 == this._y)) {
//misc checks
if (!$gameMap.isEventRunning()) {
if (!this.isJumping() && this.isNormalPriority()) {
//start event
this.start();
}
}
}
}
}
}
if (String($dataMap.events[this.eventId()].note) == '') {

if ((this._x == MouseXGrid && this._y == MouseYGrid) ||
(this._x == MouseXGrid && this._y-1 == MouseYGrid))
{
//if player clicks
if (TouchInput.isTriggered()) {
//if player is adjecent to event and event is tall
if (($gamePlayer._x+1 == this._x && $gamePlayer._y == this._y) ||
($gamePlayer._x-1 == this._x && $gamePlayer._y == this._y) ||
($gamePlayer._x == this._x && $gamePlayer._y-1 == this._y) ||
($gamePlayer._x == this._x && $gamePlayer._y+1 == this._y)) {
//misc checks
if (!$gameMap.isEventRunning()) {
if (!this.isJumping() && this.isNormalPriority()) {
//start event
this.start();
}
}
}
}
}
}

};




I'm realizing now that this code is somehow flawed, after I ended up looking into Game_Event.prototype.update and finding no code like it anywhere...wondering where exactly I got it from to modify it like this. 


In any case, it works...but then SOMEtimes it has a problem and I think it's finding that "Game_Event" is 'undefined' in some way. Not sure what the problem is, but I'm thinking it's in this code.
The issue occurs when there is NO active page on the current event.  This happens due to no page having conditions that are filled.  Checking to see if list is null before doing anything with it should solve it.
The issue occurs when there is NO active page on the current event.  This happens due to no page having conditions that are filled.  Checking to see if list is null before doing anything with it should solve it.



Gotcha, I'm gonna try to add that into the mouse script above. Thanks as always Shaz and Hudell, will edit this post soon with update... : ) I'm gonna try "if (!this.list == null) { }"...hoping it works.
just use if this.list or this._list or this.list() or whatever the syntax is.  You don't have to add == null
just use if this.list or this._list or this.list() or whatever the syntax is.  You don't have to add == null



Damn, thanks for the help...but I tried it and I get the same error.  ;_;


I've eliminated a few possibilities so far. It's not Yanflys core script and it's not Yanflys message script...It very well may be due to the fact that the NPCs use Autonomous Movement routes. Going to try to squash this today.


I'm going to try a few things today to see if I can squash the bug: 


1) copy and paste event to a test map and see if I can re-create it. I had trouble re-creating it with other events than this particular one. 


2) try to duplicate it on other maps within the game instead of just a test map


3) then finally just start picking apart the map that's causing it. 


4) update all scripts used. 


5) if all else fails, try re-writing the code to not fit inside of event.prototype.update { } but fit inside another function like the one function in where it says: if this.trigger === or whatever code does.
can you paste the code, and the exact error message (if there's a line number that'll be helpful too).  In the code above, I don't see any reference to list at all - not sure if I just missed it or if you posted a completely different block of code.
can you paste the code, and the exact error message (if there's a line number that'll be helpful too).  In the code above, I don't see any reference to list at all - not sure if I just missed it or if you posted a completely different block of code.

list is being referenced by the default "Game_Event.start" method, which is called from "Game_Event.update" which was changed in a plugin called "0_MapSceneEdits".


The error is probably on that plugin. I think that is the code that OP posted.


That code starts multiple events: My bet is that it is triggering an event that changes a switch or something and that makes the next event have no valid page, but that small script tries to activate the next event anyway, causing the bug.
This is Game_Event.start:

Code:
Game_Event.prototype.start = function() {
    var list = this.list();
    if (list && list.length > 1) {
        this._starting = true;
        if (this.isTriggerIn([0,1,2])) {
            this.lock();
        }
    }
};



so it already caters for an empty list (ie - no valid event page).


The script the OP has provided is not the entire MapSceneEdits script - that script is at least 394 lines long, and the issue is likely somewhere else in the script.  
Are you able to attach the full script?  Or at least indicate what is on line 394 of that script?
From the first screenshot, we can see that the error is triggered here:


Game_Event.prototype.list = function() {
return this.page().list;
};


this.page() is returning undefined and the error happens when accessing the "list" property of undefined.
Yeah, it's triggered there, but it's caused somewhere else.  You wouldn't want to try and fix it by changing Game_Event.prototype.list - you'd want to fix it by finding what, in the new script, is doing something wrong.  That's why it would be helpful to see the full script.
Yes, but the problem is on that snippet! It is starting an event that has no active page.


Changing it to the following will probably stop the error from being triggered, althought it also won't trigger any event (which may not be what astracat wants)

Code:
//Check if player is beside event
var alias_AstraCat_customEventUpdateForChecks = Game_Event.prototype.update;
//If an event is clicked and the player is adjecent to it, start that event
Game_Event.prototype.update = function() {
    alias_AstraCat_customEventUpdateForChecks.call(this);
    
    //if mouse hovering over event and event is small ('small' note is on event page)
    
    if (String($dataMap.events[this.eventId()].note) == 'small') {
        if ((this._x == MouseXGrid && this._y == MouseYGrid) ||
            (this._x == MouseXGrid && this._y == MouseYGrid)) 
        {
            //if player clicks
            if (TouchInput.isTriggered()) {
            //if player is adjecent to event and event is small
                if (($gamePlayer._x+1 == this._x && $gamePlayer._y == this._y) ||
                    ($gamePlayer._x-1 == this._x && $gamePlayer._y == this._y) || 
                    ($gamePlayer._x == this._x && $gamePlayer._y-1 == this._y) ||
                    ($gamePlayer._x == this._x && $gamePlayer._y+1 == this._y)) {   
                    //misc checks
                    if (!$gameMap.isEventRunning()) {
                        if (!this.isJumping() && this.isNormalPriority()) {
                            if (this.page() !== undefined) {
                                //start event
                                this.start();
                            }
                        }
                    }
                }                
            }
        }
    }
    if (String($dataMap.events[this.eventId()].note) == '') {
         
        if ((this._x == MouseXGrid && this._y == MouseYGrid) ||
            (this._x == MouseXGrid && this._y-1 == MouseYGrid)) 
        {
            //if player clicks
            if (TouchInput.isTriggered()) {
            //if player is adjecent to event and event is tall
                if (($gamePlayer._x+1 == this._x && $gamePlayer._y == this._y) ||
                    ($gamePlayer._x-1 == this._x && $gamePlayer._y == this._y) || 
                    ($gamePlayer._x == this._x && $gamePlayer._y-1 == this._y) ||
                    ($gamePlayer._x == this._x && $gamePlayer._y+1 == this._y)) {   
                    //misc checks
                    if (!$gameMap.isEventRunning()) {
                        if (!this.isJumping() && this.isNormalPriority()) {
                            if (this.page() !== undefined) {
                                //start event
                                this.start();
                            }
                        }
                    }
                }                
            }
        }
    }
    
};
Why would you say it won't trigger any event?  If there isn't an event with an active page, then you wouldn't want it to be triggered.  If that means NO events nearby have active pages, none of them will be triggered.
I mean that maybe the real issue is a wrong page condition, in which case astracat would want one page to be active on that situation but it wasn't.
Okay, nevermind, I tried Hudells code and that seems to do the trick! After I tested it about 10 times straight the error doesn't show up. Thanks, you guys are always really helpful, you should have a back and forth more, the problem was solved so quickly with that.  🙂

Changing it to the following will probably stop the error from being triggered, althought it also won't trigger any event (which may not be what astracat wants)





No, that actually does do the trick Hudell, because the event still gets triggered, but it just stops it from tirggering when the error is supposed to pop up (and the events pages in that millisecond haven't been created or whatever)...My theory is that it might be like a frame drop thing, or that there are a lot of events going on all at the same time so there's like a skip at one moment? I say this because the bug seemed to happen randomly, at random moments when the mouse would click an event.


So...to clarify for anyone who has this problem in the future, you have to do this check if you want to activate an event through it's update function: 


if (this.page() !== undefined) { }




Before starting the event with this.start. 


I was also writing it before like this, and the following code doesn't work: 


if (!this.page().list == undefined) { }


Also, I was alternatively using !=, which I don't think did anything...


Anyway, thanks again for the help guys!


Hey, thanks guys for all the support! I'm pasting the full 0_MapEdits.js file now. I hadn't had time to try to isolate the bug in the past few days but have more time to today: 


I am trying Hudells code right now, although I thought I had tried that already with (!this.page() == undefined) { }. Maybe you're supposed to do (this.page() != undefined) { } instead.


Just a note before I post the code...there was a topic recently posted here in the rpg maker mv forum: 





In where someone gets a different type error with the new update that came out on...april 22nd I believe? It doesn't seem like he's able to fix it yet, although it doesn't have to do with the page thing. 


This is going to be a bit messy as it hasn't entirely been cleaned up...but here it is. The first 60% or so of the code is just setting up and displaying a HUD. After that you have that code snippet I pasted above, and the SceneMap.prototype.processMapTouch function which I took all the code out of to turn movement through the mouse off.
HA! Thank you Shaz! conditions not met... duh! dumb mistake of mine !

Original thread: https://forums.rpgmakerweb.com/threads/what-is-game_event-list-i-get-an-error-cannot-find-list-of-undefined.61121/