playMaker

Author Topic: [SOLVED] Storing values.  (Read 5807 times)

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
[SOLVED] Storing values.
« on: May 06, 2012, 05:59:13 AM »
Hey if i store a value, will it permanently store it? EG: if the game was exited and returned to would the value still be the same? this is for storing scores and values for unlocking levels.

any help would be awesome, thanks.
« Last Edit: May 08, 2012, 10:36:07 AM by shinodan »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Storing values.
« Reply #1 on: May 06, 2012, 06:24:11 AM »
Hi,

 The way you formulated your question is interesting.

 The answer is no, but for this, there is a system unity is providing called PlayerPrefs, where you can store a key/value pair that persists when the app is existed ( works on all platforms). This is very much like cookies on websites.

 Playmaker has actions to access this, they are all in the "PlayerPrefs" category of the Actions browser. Use them to save and load informations.

 Now, why not being able to declare a variable persistent right within the playmaker interface, that would be really great and very easy for the user, behind the scene it would simply use the playerPrefs system. I'll submit this to Alex.


 Bye,

 Jean

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Storing values.
« Reply #2 on: May 06, 2012, 05:56:18 PM »
if you create a variable and set a value for its default number in the variable tab, it will retain that value between sessions, however if you change that during runtime it won't keep it.

maybe we could have some sort of checkbox that would make it permanent as an option. 


shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: Storing values.
« Reply #3 on: May 07, 2012, 10:20:44 AM »
i was going to say having a little checkbox that could permantly change a value would make it so easy to create my own savegame system and scoreboards. i wanted to have a trigger at the finish of my level that sets a bool to true, then the main menu would check for that bool before allowing you to select that level again. would be great!

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: Storing values.
« Reply #4 on: May 08, 2012, 07:28:14 AM »
hey a little bump as im confused as to how i should add a playerprefs file to my game so that i can call on it?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Storing values.
« Reply #5 on: May 08, 2012, 07:40:26 AM »
hi,

 you don't add a player pref file, it's all done internally for you  based on the platform, this is nothing to do with playmaker neither, it's a unity feature.

http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs

Bye,

 Jean

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: Storing values.
« Reply #6 on: May 08, 2012, 07:57:53 AM »
im so confused with the playerpref actions still. For example, i want at the end of each level for the player pref int to add 1 to it, then on my main menu when i hit continue it refers to whatever value the playpref is set too loading the level that i was last on. something like that possible?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Storing values.
« Reply #7 on: May 08, 2012, 09:18:07 AM »
Hi,

 Of course. I think you are over thinking this.

at the end of your level, have a state that use the playerprefsSetInt https://hutonggames.fogbugz.com/default.asp?W553

think of a name of the key like "lastLevel" or something. It must of course be unique amongst prefs in your application.

that will effectivly store an int under the key "lastLevel"

now when you open your application, check if the key exists using https://hutonggames.fogbugz.com/default.asp?W556

if true use the variable content, it will be the value you last saved, else it means this is the first time the application run or the use did not reached yet the end of the level or whatever that triggers the saving of "lastLevel"

 Does that make sense a bit more? If you are still stuck, I'll make a working example.

 Bye,

 Jean
 

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: Storing values.
« Reply #8 on: May 08, 2012, 09:40:45 AM »
I think i understand, im going to try to get that working now, thanks so much!

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: Storing values.
« Reply #9 on: May 08, 2012, 10:35:47 AM »
haha i think i overcomplicated things again, BUT! i got it working woop woop!

i have an action at the end of each level that creates a playerpref int and deletes the previous one.

on my menu i have a button that checks for the ints and loads the level when it finds it.
here is a screenshot!

Thanks alot for your help!

I love playmaker more and more each day.