playMaker

Author Topic: Please help me with Playerpref issue  (Read 2128 times)

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
Please help me with Playerpref issue
« on: June 06, 2014, 05:21:29 PM »
I asked this question on reddit but it seems to be a Playmaker issue.

I have 4 game modes. Each of the 4 game modes has its own separate high score system with its own separate Global Variables set up like this:

Current Score: INT (value goes up as player kills enemies)

Current Score: String (to show the player their score)

Best Score: String

Best Score: INT

After the player chooses their game mode and level the level is loaded, an empty game object calls Playerpref Get Int to get the current Best Score value. When the player dies or when they finish the objective (depending on the game mode) the Current score INT is compared to the Best Score INT and if the current score is higher, we set a new high score using a Set INT Value action.

From there I call a Playerpref Set Int action to save the new Best Score and we transition to a Game Over screen.

Problem 1: Each Playerpref has a different key and interacts with a different Gloabal Variable. Again, there are 4 separate values that need to be saved (one high score for each game mode). However, my Playerprefs seem to be interfering with one another. So if I save a high score in Game Mode 1, the Playerpref seems to set that same value as the high score for all game modes, even though they use different keys.

I experimented by setting the high score values for one of the game modes to use a Float value instead of an Int. When I did this, the score for that game mode was not overwritten.

The issue seems to be that the Playerpref has a problem keeping track of more than 1 value of the same type (INT/Float). If I try to save the value of 1 high score it overwrites the value of all high scores.

Is this a limitation of Playmaker or am I doing something wrong?

Problem 2: When testing the game on PC and Android my PLayerpref values do not save when I close the game. When I start the game back up all of my scores have been reset.

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Please help me with Playerpref issue
« Reply #1 on: June 06, 2014, 06:09:37 PM »
Have you thought about using a better featured save system?

EasySave2 is pretty cheap on the asset store, and it's very intuitive to use. I have no problem saving and reloading after 600 variables (bools, ints, floats, strings).

It's been a while since I was messing around with playerpref stuff, but I remember having problems with it not restoring data properly. (probably due to user error, but I gave up trying to track down the problems).

Oh, and easysave2 works seemlessly on all devices I've tested my game on.

LogLady

  • Full Member
  • ***
  • Posts: 150
Re: Please help me with Playerpref issue
« Reply #2 on: June 06, 2014, 08:03:39 PM »
I recently had problems with PlayerPrefs not loading all values correctly and the problem was that my variables couldn't be filled up in time during the scene load. So I put a global event that is fired after the scene loads telling to my PlayerPrefs FSM to start loading values and setting it into an array or just filling some variables.

Cheers!