playMaker

Author Topic: Save/load all variables to playerprefs action  (Read 6252 times)

Kubold

  • Full Member
  • ***
  • Posts: 112
Save/load all variables to playerprefs action
« on: November 27, 2012, 06:57:38 AM »
How about an Action for saving/loading all playmaker local and global variables values to disk? It can be totally generic, but it would save a lot of time on making cutstom playerprefs keys and all for let's say 150 variables. Like a savegame, but limited just to playmaker's variables to make it easy.


Example:
Player has variables like: amout of ammo, amount of health, armor, stamina, strenght, speed, max jump height etc. They get changed during runtime. If player hits "save game", the amounts get saved on disk with Save all Variables action. He restarts the computer,  and hit's "load game" - We use actions "Load all Variabls" and then "Load Level".
This would make a lot less thing's to worry about, what's left is player's position on the level, etc.

I know the rest of variables would be saved also (for example Axis values or velocity or whatever), but it would be no problem most of the time. Or solved by choosing the variables that you want to make playerprefs for, or masking the one that you don't want to save).

I'm saying PlayerPrefs is a b**ch, if you don't know how to program, and Playmaker is exactly for people that don't know how to program. Or don't like to program... same thing :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Save/load all variables to playerprefs action
« Reply #1 on: November 28, 2012, 01:09:27 AM »
Hi,

 Good idea. bump this after the 12th of december if no one stepped in, I'll see what I can do, I already have some code to scan all fsm variables so we can do something here indeed, maybe save all variables flagged as "inspector".

bye,

 Jean

[?]Anykey

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Save/load all variables to playerprefs action
« Reply #2 on: December 25, 2012, 07:00:16 AM »
bump :)

Kubold

  • Full Member
  • ***
  • Posts: 112
Re: Save/load all variables to playerprefs action
« Reply #3 on: February 11, 2013, 07:59:34 AM »
bump?.. I would really love to see some quick playmaker solution for savegames.

julius

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Save/load all variables to playerprefs action
« Reply #4 on: February 12, 2013, 10:17:00 PM »
http://whydoidoit.com/unityserializer/

I'm not sure if it will work with playmaker, but it should.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Save/load all variables to playerprefs action
« Reply #5 on: February 25, 2013, 01:11:26 PM »
I can totally see how this would be beneficial but to be honest this feels like it'd be better suited to a third-party action set if it's this specific. Also, given that it is so very specific and universal, i can see some areas that would need improvement.

If i may make a suggestion, though... (and i don't know how easy this would be) but making the action so that it only exports variables from the FSM that it's placed in, you tell it how many and then you choose the variables you want to export. that way i think it'd be much more flexible and give you more control (and for globals, you could have a "save/load globals" action)

The naming could be easy if you have a single player save state... but once you get into multiple save states, this could start to cause issues if it's just offloading all the names... so, to refine it, maybe add in an area where you can add a prefix string to the name of the variables you're offloading. so, say you want to save to player slot 1... you tell it to add the prefix of "Save1_" to each of the player prefs identifiers.

As for the interface, an int-switch approach where you tell it how many... and then each separate spot would have a "declare variable type" (or if that's too complicated, a separate action for each variable type that works like this.) and a string variable for any prefix you wish to use (or "none" if no prefix.)

I think that'd be a much smoother approach to this and it'd prevent you offloading data that isn't necessary to save (such as temporary variables used for random number generation, place-holders for passing variables between FSMs, the last enemy killed and how much experience it gave you...) reason being is that the player prefs, though big, does have it's limits and the fewer variables you need to save, the smaller that section would be.

Though, i'm not a programmer so i don't know if this would be more appropriate or easier.

if it was all flexible like that, then i would think that it'd make a perfect addition to the player prefs (though not to replace them... there are times when having direct control over specific prefs would be ideal.)

Good idea? bad idea? needs-some-work idea? I understand that this would be a beefy action set to make so i can understand that patience is more than necessary in something like this (and of course a pat on the back and buying a drink for the daring person willing to tackle this particular beast. ;) )

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Save/load all variables to playerprefs action
« Reply #6 on: March 18, 2013, 08:51:52 AM »
Hi,

 I can see why one would want to use the player prefs, but everytime I want to tackle this, I really think that

1: http://whydoidoit.com/unityserializer/ is the right way

2: if not, then using a proper database is the second best right way

 Saving all in player prefs is not really a good practice in many situations.

bye,

 Jean