Uncaught TypeError: Cannot set property 'innerHTML' of null

Anyone else get this error: Uncaught TypeError: Cannot set property 'innerHTML' of null when starting a game?

I think it happened to me when I started using the latest version of choicescript with my old games, and it’s because you need to put <style id="dynamic"></style> in index.html. It wasn’t there before, but now it’s required.

Anyway, if you update your copy of choicescript and get this error, this is how to fix it. Maybe everyone but me just replaces everything but their scenes folder when they update. LOL.

@dfabulich, think it would be good for the code to check if document.getElementById("dynamic") is null and do a head.appendChild() to create it?

Long story short, there’s no need to touch the JavaScript or HTML. Just copy the old mygame folder to a new version to update. That’s it. Anything else is just asking for more trouble.

True, but people might be running into this error and not knowing why it’s happening or how to fix it. It’d be good for the source code to error trap.

In JavaScript almost everything is an object, null and undefined are exception. When you try to access an undefined variable it always returns undefined and we cannot get or set any property of undefined. In that case, an application will throw Uncaught TypeError (link redacted by moderator).

In most cases, you are missing the initialization . So, you need to initialize the variable first. Moreover, if you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. If you just want to check whether there’s any value, you can do:

if( value ) {
  //do something

Or, if you do not know whether a variable exists (that means, if it was declared) you should check with the typeof operator .

if ( typeof(some_variable) !== "undefined" && some_variable !== null ) {
  //deal with value

Hi @warrenfelsh , welcome! Yup, that’s what I would do if I were Choice of Games.

Please don’t resurrect threads without good reason. Actually suspecting the account is a bot.