PlayMaker Help & Tips > iOS Help

Set PlayerPref and Get PlayerPref not working with store variable~!

(1/2) > >>

san:
Hi, everyone so i have a question with how to save data or store data in one scenes and carry to another scenes….

so i setup the first scene has set int value to 0 - this will do 0 whenever level 1 start ~!
Same level - i set player pref and int variable…
Same level - number of scores has add into same variable by 1 and covert into string and gui-text shows score…so lets says… level 1 has 20 scores in the end of the level 1
Same level - those add int 1 variable add into set player pref int variable ~!
level finish ~! go to menu…. in the menu page i set up Get playerpref int with same string and same int variable…
and covert those int variable into string and set textgui using that string… to see the score…


So the problem is… in the first level i get XXXamount of scores number and put all those add int value number into set playerpref…. variable
but the set playerpref int variable having problem with not carrying store data into menu scenes.

so i am wondering because i set int value to 0 in the begining…? maybe because every time level is finish set int value = 0 … is that why the data is not carrying over to menu page?

so i did another test without using set int value = 0 from level 1.
what happened is… the int add value are adding to score… and i still have my set playerpref and int variable…
let says the game is end with score 15… - menu page pop up…
In the menu page, i just put gut-text with same int value variable number. scores are shows up in the menu page..
but the problem is… i have not use Get playerpref int …..
I only use gut-text with same converted string from level one every time int value add is adding number.

So in menu page.. when i use Get player pref int and those int value convert into string and set gui-text using that string… is showing nothing…
is it because level are loading and playerpref variable data lost by opening another scenes ?

And i am using all global variable…

please help.

Oh and one more thing.... unity ads still not working ~! lol. i want to release this test game but i am having this get and set playerpref issue. if anyone can help please do.  thanks

djaydino:
Hi,
Playerprefs get/set seems to work fine on my end.

Did you check if the key name on both actions are the same?


--- Quote ---And i am using all global variable…
--- End quote ---
This is actually a bad thing, try to minimize using globals.
Globals are easy to hack and get messy the more variables you get.

Groo Gadgets:
Heya,

The playerprefs actions work fine, I think the problem is how you are implementing them into your game.

First thing I would suggest is picking up an asset that lets you view all playerprefs in your project. I personally use EasySave since you can extend the data you save into arrays. This asset might be overkill for your project so if you just want to view the playerprefs in your project then Advanced Playerprefs Window might be for you: https://www.assetstore.unity3d.com/en/#!/content/7070

Next, you should experiment in a new scene to get playerprefs working the way you want. If you have only one high score per level this should be easy. If you have more than one score per level then you should consider using EasySave since that asset lets you save arrays. You can, of course, create an array variable and convert it to a string to save into playerprefs.

You need to create an FSM that compares the existing score in your playerprefs with the score that the player just achieved in your level. If the score is lower then do nothing, if the score is higher then set the new score to the playerprefs value.

Does this make sense? I agree with djaydino, you should not use globals when saving and loading scores.

Cheers,

Simon

san:
Hi Djaydino, Thanks for relpy ~! i didn’t set up Pref-key before ~! But since you reply i have been testing with Pref-key and still having an issue.

The problem is now Pref-Key-False_event > set playerPref always active whenever the game is restart or play again. and not going into a True_event > get playerPref > convert int to string and set gui text. (is not doing that)
Every time the game restart, the pref has key is going into False event and set a PlayerPref.

I did clearly wrote all global variable clearly so that wasn’t an issue.. Just setting and getting pref is problem.

So this is what i did, on main menu page - just one button to click play the game and text score on top .
- Start state to playpref has key - give two event state (true event and false event) true event goes - Get Pref / false event goes - set Pref and i put 0 on variable.
- In the Get Pref, I gave a int and string variable > finished > i have convert string and set gui text to see the score.

In the game - i have set up a Prefab box that pass by right to left screen so one box pass 1 int add value… with trigger enter.
-Eveytime box enter i send an event to another empty gameManager that has adding int value and converting int to string to see the score in the game.
-So in that game manager i set up like this again > Start State to PlayerPref has key - give two event (true and false event)
- true event goes to Get PlayerPref > finished > convert int to string
- False event goes to Set PlayerPref > finished > convert int to string, this state event finish go to (listener state) that is receiving event from box trigger > go to int add value state and i loop back into convert int to string state again.

So when the player die go back to main menu page and so i keep play for twice and the PlayerPref has key is going False event > Set playPref state… not going into Get playerPref state to see if previous score is higher or lower… not doing int compare.

I had this problem past 4 years ago and i couldn’t pass this get and set pref level even i was able to manage setting all level and Ai expect getting and setting data, i really do need help. Can you do video tutorial for this?

Thanks

san:
First image is intro page.
Please take a look~! i think i am doing it wrong, please see which part i need to fix.
so everytime the game is start its going into set_pref. Not going to Get_pref.

Navigation

[0] Message Index

[#] Next page

Go to full version