How do I detect if the game is run for the first time?

0 favourites
  • 12 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • I've tried different ways with localstorage but I seem to be missing some intellectual understanding of how localstorage works since it works but it's spotty.

    Any other alternatives? I want to have a mini tutorial at the start of the game, when the game is run for the first time. I'm working with CocoonJS and iPhones btw. Just in case it's relevant.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK I found how localstorage could work.

    and it works consistently now. I don't understand it but I'm in panic release mode soon oh dear must hurry up, and I can't do it now. Thanks for reading anyway.

  • Nope, doesn't work on iPhone now. LocalStorage is seriously hurting my brain stem.

    So the question still stands, any solution oh wise Construct2 world?

  • I learned how to use localstorage by looking the following tutorial

    https://www.scirra.com/tutorials/1461/h ... age-plugin

    Also, I had a problem when using the ludei/cocoon site. I solved this problem when I exported using cordova, that is already in construct 2 options (paid version). I exported only for Android devices (apk file).

  • nemezes, thanks. That might help, but I'm exporting for iPhones not Android.

  • Why use a "Trigger once" instead of "On start of layout" ?

    Also, on first execution, the key won't exist. So instead of attempting to "get" the key, you should first check if it exists.

    If it doesn't, then you can assume this is the first execution, and you can create your key.

    On next execution the key will exist, and then you can skip the tutorial or whatever you want to do, knowing the game already has been executed.

    As it stands the code from your screen copy won't work on any device you never created the local storage key first.

    Consider checking the Score System implementation in that tutorial.

  • Kyatric "Also, on first execution, the key won't exist. So instead of attempting to "get" the key, you should first check if it exists.

    If it doesn't, then you can assume this is the first execution, and you can create your key."

    Tried that, Didn't work for me, so I tried with this. I actually got it to work now somehow on the iPhone. But it's black magic and beyond my understanding. Will read up more about this but I'm afraid it might be a CocoonJS incompatibility or something.

  • Kyatric, if I LOAD SAVE or Restart Layout, would "OnStartLayout" still work? Because I don't want it to

  • I have found the way of doing this in my game

    Compare your "Score" Key value

    at first time your key "Score" value is zero

    so set

    if "Score" = 0 > hen you can do anything in action

    Edit : Oops ! You already get the idea, I didn't read your answer properly.

  • Thanks maybe it will be clearer to someone else needing this

  • On start of layout will happen every time the layout is started. Whether it is in the same execution, or not.

    Nevertheless, when you are executing your game on a device for the very first time, there is NO local storage key existing on the device for the game.

    So you know you want to display the tutorial.

    Also, your code is supposed to be made so that when a key doesn't exist, it creates one.

    Once the game has been executed once, the key has been created, the next time the layout is started (whether in the same execution, or later), "On start of layout" checks if the local storage key exists. This time it does.

    So you go to a different event, in which you remove your tutorial elements.

    It's the logic of how local storage works.

    No magic this way, and you are using the local storage how it is supposed to be used.

  • Kyatric My mistake was that I wasn't checking if it existed, I just jumped to on missing. Got it now thank you!!!

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