playMaker

Author Topic: keep score across levels  (Read 3886 times)

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
keep score across levels
« on: July 29, 2014, 06:18:43 PM »
Hi

I have tried to find the answer in the forums with no luck so i'm asking in a new thread.
Basically i have gui text system displaying health and score managed by a global fsm system (based on christ. Orth health manager tut). The idea for my game is that when you have finished one level you will unlock the next one and continue to upgrade your score / keep upgrade your health.
My issue is when the player is finishing a level and back to main menu i can't keep the datas (health and score). Any idea how to do this with playmaker or do i need an extra plug/asset ?
Thanks
Emmanuel

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: keep score across levels
« Reply #1 on: July 29, 2014, 09:15:00 PM »
You need to store this information as Global Variables, that way they are maintained across level loads.

If you want to save them as well, so they are restored when the user quits and reboots the game, then you'll need to use PlayerPref (search the forum) or a save data plugin (e.g. EasySave 2).

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
Re: keep score across levels
« Reply #2 on: July 30, 2014, 09:42:57 AM »
Hi
Thanks for your answer
I have created a FSM with global variables called health manager but i can see that is not the case for all my variables used for score. I will dig into this and let you know

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: keep score across levels
« Reply #3 on: July 30, 2014, 11:19:01 AM »
Global Variables are not created on FSMs. You need to open the PlayMaker / Editor Window / Global Variables window from the top Unity bar.

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
Re: keep score across levels
« Reply #4 on: July 31, 2014, 11:40:55 AM »
Hi
Yes i know this and all my variables are created as global
Attached is the FSM sticked to the main character
Everything is working fine inside the level but when i move to a second level (load level / don't destroy on load) my score is back at 0...
Any idea what i'm doing wrong
Thanks

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: keep score across levels
« Reply #5 on: July 31, 2014, 11:56:42 AM »
Try changing your Score states to Action Sequence. If you have them all running at the same time, your Int to String will be running before your Int Add has actually added 1 to your value, and your GUI text will be set before the 1 has been added also.

At the bottom of your State area, there's a checkbox called Debug.  Switch that on, then you can see the values of each action/variable as you're testing. It's very useful, then you can see if something is getting a value before you want it to.

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
Re: keep score across levels
« Reply #6 on: July 31, 2014, 12:15:22 PM »
Hi
Each score state is linked to a different "tag" and all is working fine inside the level. Got points added and deleted. My main issue is that when i finished the level and enter next level my GUI text is back to initial value not the final score of the last level? Is it clear...sorry for my bad english...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: keep score across levels
« Reply #7 on: August 01, 2014, 06:22:42 AM »
Hi,

 You should use PlayerPrefs for this. This has an added benefit of being completly separated from potential value reset amongst level loading, AND you can keep track of that if the player quits and restarts the game.

 But with your GameData Editor, don't you have this built in already?

The trick usually that I apply for this, is to create a "singleton" that I set to persists across level loading ( "Don't destroy on load" action ), and then if you load a level, the variables values will not be reseted and your score logic can rely on what will be available on that object.

 Does that make sense?

Bye,

 Jean

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
Re: keep score across levels
« Reply #8 on: August 01, 2014, 10:40:05 AM »
Hi
Thanks for the explanation
The problem is that the score system is not on an empty game object but on the player... so guess this is not going to work with don't destroy on load...will have a look at the playerprefs or will have to rebuild the whole thing...
bye
E

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: keep score across levels
« Reply #9 on: August 01, 2014, 03:01:21 PM »
Hi,

 It's a good idea to spread things. Indeed here, PlayerPrefs will save ou. Everytime you load a level, simply save data before, and when you instantiate your player again, read from the playerprefs always, and then data will sustain.

Bye,

 Jean

daidokoro

  • Playmaker Newbie
  • *
  • Posts: 17
Re: keep score across levels
« Reply #10 on: August 02, 2014, 05:46:46 AM »
Hi Jean

Thanks for the explanation. I will look into playerprefs

E