WebStorage into Array question

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm storing items the player collected (CurLevel,0 (can be 1 through 3)) in an array (named LevelComplete) at the end of the level then storing those stats into WebStorage.

    WebStorage then loads that info at the start of the game.

    A problem occurs when I try to check the value in the array where webstorage already posted data saved previously from another session.

    When using "Compare two values" or "Array: Compare At" the events are not triggering even though they should, but using a proxy like saving the array value to a Text object and then comparing the text to the array value the events trigger normally.

    <img src="https://dl.dropboxusercontent.com/u/35440583/C2Forums/C2Events.jpg" border="0" />

    Another thing is that using "less or equal" or "greater or equal" instead of "Equal to" the events go through fine as well.

    <img src="https://dl.dropboxusercontent.com/u/35440583/C2Forums/C2Events2.jpg" border="0" />

    I'm not sure if this is some kind of a bug with using equal to or am I just not understanding how Webstorage works correctly.

  • Have you tried putting quotation "" marks around the "2"?

  • Putting quotation marks works if the array value comes from webstorage, yes.

    But then if the array was filled regularly with a number, as it originally does after first beating a level, the events do not trigger.

    Now my question is shouldn't numbers stored in webstorage from an array be numbers and not a string?

    EDIT: And why do "less or equal" and "greater or equal" work but "equal" doesn't when the number isn't presented as a string (no quotations)?

  • Basically using both "greater or equal" and "less or equal" I can get the same condition as "equal to", with the latter not triggering the events.

    <img src="https://dl.dropboxusercontent.com/u/35440583/C2Forums/C2Events3.jpg" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The WebStorage manual entry notes:

    ote WebStorage only stores strings. If you set a key to a number like 100, when you retrieve it back it will be a string. To convert it back, use the system expression int, e.g. int(WebStorage.LocalValue("score")).

    So you're probably getting the value back from WebStorage as a string "2" rather than the number 2. Make sure you convert it back to a number when reading from WebStorage if it's supposed to be a number.

  • Many thanks.

    Could you explain why less and greater are working when one of the variables is a string with a number, but equal doesn't?

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