playMaker

Author Topic: PlayerPref attempt - need feedback  (Read 2256 times)

jayf

  • Playmaker Newbie
  • *
  • Posts: 40
PlayerPref attempt - need feedback
« on: January 03, 2015, 10:38:41 PM »
Hi.

So this is my first time trying PlayerPrefs. I want to create a system that unlocks and make things stay unlocked. What I did was save the current Level the player reached (as a Float Variable) and converted it into a String called str_Level_Nr.

Which then gets saved into a Float Variable called "pp_Level_Nr". I was hoping the level gets saved as a PlayerPref somehow, so the icons which are supposed to get unlocked, can constantly check pp_Level_Nr and remain "open". Example: If pp_Level_Nr = 4 then unlock icons.
They do unlock after the player reaches a certain level but after some time, the icons go back to being locked. So apparently, things don't get saved. Am I doing things correctly?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: PlayerPref attempt - need feedback
« Reply #1 on: January 04, 2015, 11:22:33 PM »
in the playerprefs action :

key = the file name where it will be saved.
so in your setup you are saving the variable as a playerprefs name

in "set int" and "get int" :
change the key and give it a name (LevelReached for example),
in the value set the variable that holds the current level.
use int instead of float, unless you use levels like this :1.2, 1.3

then you need to use a int compare that will check if you current level is higher than the 1 saved in playerprefs. else it will overwrite it.

if you want to see what is going on whit your playerprefs variables, there are several playerprefs viewers/editors in the asset store

jayf

  • Playmaker Newbie
  • *
  • Posts: 40
Re: PlayerPref attempt - need feedback
« Reply #2 on: January 05, 2015, 07:05:18 AM »
Hi djaydino.

Thanks for the reply. I tried out your suggestion and it seems to work fine. I can unlock something after reaching a certain level. However after a couple of hours or so, the stuff that's supposed to be unlocked is gone.
I posted my FSM setup hoping it helps. I have a PlayerPref game object that's responsible for saving the number of levels the player has reached into an Int Variable, which then gets saved into another Int Variable.
Now on the icon itself that's supposed to unlock, I have an FSM.
1) Checks if player has key.

2) Compares the saved Variable from the PlayerPref manager. If the number is equal to let's say 4 it should unlock.

Like I said it unlocks just fine, however it doesn't seem to be saved somewhere?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: PlayerPref attempt - need feedback
« Reply #3 on: January 06, 2015, 10:58:49 AM »
when you press play does it stay on the first state (where the "has key" action is)

or does it continue to the next state?

if it goes to the next state then it is saved, but maybe then there is something happening with the value.

maybe you can check it :

enable Debug (bottom, right side of the playmaker window)

press play and check the values from pp get int, pp set int and int compare if they are the same

also be sure that pp get int runs before int compare runs.

i still recommend you to get a playerprefs editor from the asset store, they start from $5