I trying to make a script and I want it to first find all the events within the map that the player is in.
However I seem to get an error saying:
Code:
TypeError: Cannot read property 'events' of nullThe line of code its having trouble with is very first like of this for loop.
for (var i = 0; i < $dataMap.events.length-1; i++) {
var note = $dataMap.events.note;
var note_args = note.split(" ");
var note_id = note_args.shift().toLowerCase();
var piece_num = Number(note_args.shift());
if ( note_id == "piece") {
puzzle_pieces[piece_num].push(i);
}
}
This for loop is not inside any function, besides the main (function() { })();
Correct me if I'm wrong, but I think the error is coming from the fact that the script is loaded before the map is.
If this is true, how do I make the script wait?
If not what is causing this error and how should I fix it?