Localstorage not working properly?

Get help using Construct 2

Post » Wed Sep 20, 2017 12:13 am

I even put the global variables "HighScorePass" and "Score" in their own event sheet, and included that event sheet in both the level sheet and menu sheet. The menu screen is suppose to show the highscore, but when I try to load from local storage, I get a 0. I tried reading other examples, but somehow, when I test, local storage will not pass unto the global variable. I think local storage is finally working, but it just won't pass into the global variable and isntead resets it to 0.

The game itself:
http://theefenders.fulgryph.xyz/KnightNight5

Notice that if you hit refresh, the score resets back to 0?

Here is the screenshot from the menu event sheet:
Image

From the level, where the score gets saved. (Scoresaver variable is only to prevent some buttons from being clickable until after the heroes defeat).
Image

Am I writing it wrong?
Image

EDIT: The stuff thats crossed out is from my various attempts to get localstorage to work. At first it was saving as words, then finally got numbers showing up in debug mode, then NaN for a while, then numbers, and although local storage appears to save the actual highscorenumber in the debug data, instead of loading into the HighScorePass to display in the text on the menu, it just shows as 0.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Wed Sep 20, 2017 1:18 am

I think the problem is in the "On item HighScorePass Get" event.
You need to remove the Wait.
Re-enable the line where you assign the LocalStorage.ItemValue to your variable.
And remove the same line from the On Start of Layout.

Local Storage events are asynchronous, you need to follow the specific rules when reading/writing to Local Storage.
See this recent thread for some examples:
how-do-i-store-data-in-local_t195887
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
72
Posts: 1,095
Reputation: 39,253

Post » Wed Sep 20, 2017 4:15 am

@dop2000 Thank you! It is working now!! There was no way I would have seen that, I probably would have gone a more covulated route in my frustrated state.

It's quite funny, since the graphics and animations where the easy part for me. I never hit a brick wall or obstacle when making the art. The time it took me to try to solve this bug before posting on here, I would be done with a 3D model of a new enemy character(although the animation set would take an entire day or two). (Which I do by using a 3D program to make the model, then making pseudo-3D sprites from the animations of it.)

I really should team up with somebody to handle the programming side of stuff for the next game, so I could have more time to work on the graphics. : / Had I done it for this game, I would have 5 more enemy characters, and 3 to 6 more playable heroes, all with finished animation sets.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Wed Sep 20, 2017 4:43 am

I'm glad it worked :)
It's a complete opposite for me - I have many years of programming experience, so all the coding in C2 is a piece of cake. What I struggle with is graphics and visual effects.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
72
Posts: 1,095
Reputation: 39,253

Post » Wed Sep 20, 2017 3:10 pm

Thanks again. : D I only do 3D and pseudo-3D sprites now, totally retired from 2D spriting as I'm not as efficient in it. I still do 2D illustrations though.

Amazing how people can specialize in different things. How easy would it be to implement multiplayer in the type of game I'm working on? Like 2 player same screen local, or via connecting to another android phone so two different people can play simultaneously?
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Mon Nov 06, 2017 5:44 am

@dop2000 Is there anyway to save and load images from H5 Local Storage using C2?
B
10
S
1
Posts: 15
Reputation: 498

Post » Mon Nov 06, 2017 5:57 am

@kentoy
What's "H5"?
I haven't tried this, but there are 2 plugins to convert images to/from string (which you can save in local storage):
viewtopic.php?t=68494&start=0
viewtopic.php?t=68521&start=0

Links in those posts are dead, you can download the behaviors from github:
https://github.com/JohnnySheffield/C2_Plugins_Pode
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
72
Posts: 1,095
Reputation: 39,253

Post » Sun Nov 12, 2017 6:22 pm

@dop2000 thank you so much!! you are sweat!...I will try to learn from the links!
H5 I mean HTML5
B
10
S
1
Posts: 15
Reputation: 498


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests