Help Needed on Webstorage

0 favourites
  • 2 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • So I'm working on a game which has multiple characters whose stats can be modified, so I built this test to see if I could store said stats in webstorage.

    Capx here: dl.dropboxusercontent.com/u/23727205/webstoragetest.capx

    What I'm doing is spawning a random instance from the family 'animal'. Every animal has an attack and speed number. When the layout starts it looks for an entry in webstorage, and if there isn't one it tries to default the values to 1 so that their display bars are the right width.

    MAIN ISSUE

    If you clear webstorage and keep restarting the layout sometimes the attack and speed values are 0, so the bars have 0 width and the saved value ends up being 0 which for our intent and purpose is invalid. I can't for the life of me figure out why. I have a quick fix event in there that checks if they're 0 and sets to 1 but I feel that isn't robust enough. For starters, the initial value is already set to 1 in the family instance variable properties. Shouldn't it default the values?

    SECONDARY ISSUES

    I ended up having to hard code an instance variable called 'name' in order to display the correct instance name. ideally i wanted to be able to reference the specific name on spawn by calling animal.name to set the text but apparently i don't have access to it through the family. is there another way?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • FIXED: Just had to remove the 'On Start of Layout' clause from the event.

    Although I'm still unsure why the default values for the family instance variable aren't being inherited.

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