Sign in to follow this  

Local Storage/JSON parsing error with Arrays in Phaser 2

Recommended Posts


I'm fairly new to Phaser 2 and using Local Storage. I am getting errors when parsing my levels array. 0 is unlocked, 1 is locked. Unlocking the first 2 levels works great with Local Storage. When unlocking level 3 and refreshing the page, I get the following error:

"Unexpected token , in JSON at position 1" in the boot.js file:

    if (JSON.parse(localStorage.getItem( === null) {
      localStorage.setItem(, JSON.stringify(;
    } else { = JSON.parse(localStorage.getItem(;

Setting local storage after completing a level:

if ([] == 1 && < {[] = 0;
      localStorage.setItem(, JSON.stringify(;

Initial global variables in game.js = {
levelsArray: [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,],
level: 0,
localStorageName: 'savedLevels'




Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.