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

Get help using Construct 2

Post » Wed Jun 22, 2016 9:20 am

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.
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Wed Jun 22, 2016 9:39 am

OK I found how localstorage could work.
Image
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.
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Wed Jun 22, 2016 8:18 pm

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?
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Wed Jun 22, 2016 10:11 pm

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).
B
74
S
34
G
69
Posts: 235
Reputation: 40,471

Post » Thu Jun 23, 2016 8:54 am

@nemezes, thanks. That might help, but I'm exporting for iPhones not Android.
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Thu Jun 23, 2016 9:31 am

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,329
Reputation: 71,300

Post » Thu Jun 23, 2016 10:15 am

@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.
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Thu Jun 23, 2016 10:16 am

@Kyatric, if I LOAD SAVE or Restart Layout, would "OnStartLayout" still work? Because I don't want it to :)
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Post » Thu Jun 23, 2016 11:26 am

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.
Image
B
72
S
41
G
48
Posts: 688
Reputation: 34,292

Post » Thu Jun 23, 2016 1:05 pm

Thanks @Luckyrawarlucky maybe it will be clearer to someone else needing this :)
B
39
S
6
G
1
Posts: 306
Reputation: 2,948

Next

Return to How do I....?

Who is online

Users browsing this forum: kurtbal and 10 guests