How do I use math with WebStorage?

0 favourites
  • 5 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • So I have a problem where I need to use WebStorage, but for a event I only need it to add a number. (The stored key is an integer).

    Tried making so:

    Click on Button -> Set local key "StoredKey" to "WebStorage.LocalAt(StoredKey) + 1"

    But it doesn't seem like C2 accepts me putting in the "+" sign. How would I do if I wanted to add 1 to the stored value?

    IE: If key "StoredKey" would currently be 3, when I click my button it would add 1 and it'd be 4

  • It tells me "+ does not work with 'string' and 'integer'"

  • Use int() to convert a string to an integer and str() to convert a number to a string.

    The value in webstorage is always saved as a string.

  • Click on Button -> Set local key "StoredKey" to str((int(WebStorage.LocalAt(StoredKey)) )+1)

    Something like this

    Also you could use a global variable to intermediate this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, fixed it!

    Also you could use a global variable to intermediate this.

    I tried playing around with global variables but it seemed much more easier and better to use local storage directly instead of having it to save the variable to a storage and then load it, I felt like it may be cleaner just to do it like this, but thanks!

    Thread can be closed

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