Error. Value cannot be Nan

Error Alert
value cannot be NaN

Enabled Mods:

Game Dev Tycoon Mod API by support@greenheartgames.com
Percentager - Feature Focus Percentages by Chad Keating
TooManyTopicsMod by Vega27
Staff gain experience from games by William Hunt
CompetitorMod by kristof1104 and DzjengisKhan
Learn By Doing by Boom Blockhead
DLC Mod by austenke
UltimateLib by Francesco Abbattista and Chad Keating
Xtra Topics by Death the Kid
Itari by GTA Mods
Expansion Pack Mod by DzjengisKhan
The RPT Expansion Pack by Zyperspace
Game Version: 1.5.28

Platform: Windows

Distribution: Steam

This is what it says when my game crashes.

This used to only happen occasionally but now I can’t play because it happens every time I sign in! Can anyone help me with this problem?

So I was able to reproduce the error. Initially I was passing an object method as a handler for an event which resulted in the strange NaN, Undefined behavior.
... start() { this.showDevTools() this._iteration = new Iteration(this, 2) GDT.on(GDT.eventKeys.gameplay.weekProceeded, this._iteration.weekPasses ); } ...

You will notice that the handler is passed with a reference to this however this keyword is always easy to trip on. If we assign the value of this to the parent scope in a variable named _this then wrap the weekPasses invocation in a function, we can get the desired behavior.

`
start() {
_this = this;
this.showDevTools()
this._iteration = new Iteration(this, 2)

GDT.on(GDT.eventKeys.gameplay.weekProceeded, function() {_this._iteration.weekPasses() });

}
`

Now the weekPasses method works as expected and the peasants rejoice!

Happy Coding
Steve

1 Like