How do I check if my array is empty?

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello!

    I'm trying to check if my array is empty, but it's not working and I'm not sure why.

    So I load my array here. This works.

    Then I do this to check, I would like some buttons to get destroyed when it's actually empty.

    Here's an image where you can see the array is empty on the width, but the buttons are still there.

    I've also tried with this, but the result is the same :(

    Anybody know what am I doing wrong? Thank you!

    Tagged:

  • Where do you have that "is empty" check? It should be performed AFTER the array is loaded from AJAX or Local Storage.

    I'm guessing the check is done before the data is loaded from LS.

    You need to change how you load the data. I assume you want to try loading from LS first, and if LS data doesn't exist, then load the default data from the project file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Where do you have that "is empty" check? It should be performed AFTER the array is loaded from AJAX or Local Storage.

    I'm guessing the check is done before the data is loaded from LS.

    You need to change how you load the data. I assume you want to try loading from LS first, and if LS data doesn't exist, then load the default data from the project file.

    Empty check is on start layout.

    For the data that you commented I had no issue loading as it is.

    (update)

    I took it outside as a separate condition and it works! (I wanted it to check this just when I load the layout, since I hide it in a diff way if it becomes empty while you are in the screen)

    Thank you!

  • If "StorageLoad2" function loads data from Local Storage, then you should wait for it to finish. LS operations are asynchronous, which means that they take some time to finish, while the rest of your code keeps running. So yeah, that's why your "array is empty" check was not working.

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