Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

TypeError Problem

jaye

Villager
Xy$
0.00
I am creating a custom save screen script and I am adding the location when saving a game. It works fine the initial save, then when you return to title it works. The problems comes when you refresh the game or close and open it again. When I do that the 'type error' message pops up. It says, "Can not read property of 'name' null." or "Can not read property of 'DisplayName' of null". The code I am using is:

$gameMap.displayName()
 

CT_Bolt

Global Moderator
Staff member
Resource Team
Xy$
0.02
I am creating a custom save screen script and I am adding the location when saving a game. It works fine the initial save, then when you return to title it works. The problems comes when you refresh the game or close and open it again. When I do that the 'type error' message pops up. It says, "Can not read property of 'name' null." or "Can not read property of 'DisplayName' of null". The code I am using is:

$gameMap.displayName()
Totally guessing here...

Looks like you might be attempting to get a name before the map gets initialized (or at least the name variable hasn't been set).
Not sure about a real fix for your problem but have you ever looked into error trapping?
I think the Try Catch code block could help solve your issue.
Type Error
A TypeError is thrown if you use a value that is outside the range of expected types:
Example
JavaScript:
var num = 1;
try {
    num.toUpperCase();   // You cannot convert a number to upper case
}
catch(err) {
    Console.log(err.name);
}
This might solve your issue:
Try using this...

JavaScript:
try {
   $gameMap.displayName();
}
catch(err) {
    Console.log(err.name);
}
Instead of...
JavaScript:
$gameMap.displayName();
This will catch the error but you still might not get the results you need. (cool)
Let me know if this helps at all. Again... a total guess.
 
Last edited:
Top