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
37
S
6
G
1
Posts: 301
Reputation: 2,865

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
37
S
6
G
1
Posts: 301
Reputation: 2,865

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
37
S
6
G
1
Posts: 301
Reputation: 2,865

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
69
S
33
G
69
Posts: 220
Reputation: 40,216

Post » Thu Jun 23, 2016 8:54 am

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

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
291
S
114
G
95
Posts: 7,290
Reputation: 70,138

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
37
S
6
G
1
Posts: 301
Reputation: 2,865

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
37
S
6
G
1
Posts: 301
Reputation: 2,865

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
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Thu Jun 23, 2016 1:05 pm

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

Next

Return to How do I....?

Who is online

Users browsing this forum: AndreasR, Blendi1223, kellehk and 22 guests