How do I determine whether there is saved data in LocalStorage?

0 favourites
  • 6 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • When the first scene is loaded,

    I want to check if there is an Id in LocalStorage,

    and perform various processes accordingly.

    If the Id does not exist, I want to transition to the START scene.

    However, in my project, if the data does not exist, it does not go to START and falls into an infinite loop.

    What should I do?

    Also, Is there any good way to debug?

    Do I have to delete the user or storage in the browser to handle this?

  • 'get' triggers even if it's missing, I think you are using 'get' when you mean to use 'exists'.

  • Even though I made the following changes, it still results in an infinite loop.

  • What outcome are you expecting ? Also I just noticed the condition says less than 0 so what is id variable default value ? and also that event seems unnecessary in general ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I thought 'on item "" exists' would trigger when there is an existing LocalStorage 'key', but that doesn't seem to be the case. I tried debugging, but it didn't pass through this process.

    Expecting

    When playing the game from the beginning and transitioning to the start,

    I want to transition to a different scene if the id has already been stored from the previous session.

    Default Value of Id = -1

  • You need an 'on item get' then 'check item exists', then you can use the on item exists condition. I think you are missing this beforehand. But even with this, your id exists actions don't go anywhere except to Start layout, so on that first event in the previous screenshot you need to add an action to go somewhere else other than Start.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)