playMaker

Author Topic: Saving Best Time in PlayerPrefs [SOLVED]  (Read 4198 times)

Nikolasio

  • Playmaker Newbie
  • *
  • Posts: 23
Saving Best Time in PlayerPrefs [SOLVED]
« on: August 08, 2016, 01:01:00 PM »
Hi,

I measure the player's time (the lower the better) in a Timer FSM (see screenshot 1)
Then I create a PlayerPrefs: Best Time FSM.
With PlayerPrefs Get Float I want to get the variable lastBestTime ( see screenshot 2). I set this float initially to 99 so that with the first game the player plays, he will always have a first best time.
Then I do a Float Compare to see if the the player's time bettered the lastBestTime (see screenshot 3).

So with time measurements under 10sec (<99), it never flows into the New Best Time State. Has this anything to do with the Float Add per Second for the time variable?

My second question is about saving a time measurement in the PlayerPrefs (see screenshot 4).  I try to save the time variable (which is the new best time) in the PlayerPrefs and then convert it to show it in the GUI.
But for the next game, which value will be read for the practiceBestTime Key if I replaced lastBestTime with the new time and then with the next game ask again for the lastBestTime?

I tried to look here at a sample from Jean (where he saves time measurement in the PlayerPrefs) but it seems to be empty:
http://hutonggames.com/playmakerforum/index.php?topic=2596.0
Does anybody have other examples?

Grtz,
Nikola






 

« Last Edit: August 15, 2016, 09:11:34 AM by Nikolasio »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Saving Best Time in PlayerPrefs
« Reply #1 on: August 08, 2016, 06:01:02 PM »
Hi,
You should have a playerpreffs has key action @ the start of your game,
if it is not yet there then set the value to 99

i made a gif on how i set it up :


Nikolasio

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Saving Best Time in PlayerPrefs
« Reply #2 on: August 09, 2016, 11:13:05 AM »
Thank's a lot for your answer.

I've put the Check Key state in and follow the same flow with the same variables.
It flows nicely into the Set New Time state now and I can display the best time in the UI.
But it doesn't save the new time in the PlayerPrefs. I put a breakpoint on the Check Key state and every time I replay the scene it goes via the Create Key state.  So every replay of the scene is a new best time and thus it never flows in the 'no new Hs' in the Compare Time state.
I have a best time script running on another scene, which does exactly the same, but the PlayerPrefs Key just differs in a capital vs lowercase letter.  I suppose it hasn't anything to do with that? (edit: it doesn't, changed key name and the problem remains) 
« Last Edit: August 09, 2016, 11:21:34 AM by Nikolasio »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Saving Best Time in PlayerPrefs
« Reply #3 on: August 09, 2016, 06:24:03 PM »
Hi,
when i was making this i accidentally had the "playerpreffs has key" true false the wrong way around, so you might wanna check it out.

Also use a different key name than the variable.
And turn on debug will help seeing better what is going on :)
(it is on the bottom right part of the PM window)

Nikolasio

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Saving Best Time in PlayerPrefs
« Reply #4 on: August 14, 2016, 07:42:39 AM »
Hi,

I've been able to look at the sample from Jean and tried to find the problem with the debug.  But I didn't succeeded, it will not save the new best time variable in the PlayerPrefs.
I made a repro scene, could you have a look at it?

Grtz


 

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Saving Best Time in PlayerPrefs
« Reply #5 on: August 14, 2016, 10:30:35 AM »
Hi,
If you are using globals you need to export those :
click on playmaker/tools/Export Globals,
and save in your project folder and include when exporting the package.

Nikolasio

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Saving Best Time in PlayerPrefs
« Reply #6 on: August 15, 2016, 05:06:33 AM »
Hello,

Thx, indeed, I figured that out, but didn't want to send all the globals. Made a new project with the respective globals. 
Btw, is there a way to select globals while exporting?

Cheers,
Nikola

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Saving Best Time in PlayerPrefs
« Reply #7 on: August 15, 2016, 07:54:03 AM »
Hi,
No that is not possible,
but i hope that it will not be needed soon.

i made a video explaining what you have to do :


Nikolasio

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Saving Best Time in PlayerPrefs
« Reply #8 on: August 15, 2016, 09:10:27 AM »
Wow!  Thank's a million!

It's because of people like you that beginners like me can grow in making games with unity/playmaker.

Respect and definitely SOLVED!



djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Saving Best Time in PlayerPrefs [SOLVED]
« Reply #9 on: August 15, 2016, 05:58:37 PM »
Hi,
Happy to help :)

I will try to make a tutorial video for playerpreffs soon and add it to my website.