Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: dudebxl on April 08, 2015, 11:52:49 PM

Title: Saving Array to PlayerPrefs
Post by: dudebxl on April 08, 2015, 11:52:49 PM
I had a dream.. My dream was to save an array to playerprefs so here we go..  ::)

Description
Save any type of array to playerprefs using the playerprefsx extension. Tested with bool + int + color array. Should work with all other variables (have not yet tested   :( ) so pm if something is wrong.

Usage

Requirements
source: https://hutonggames.fogbugz.com/default.asp?W714

Also compatible with PlayerPrefs encryption (also found in add-ons) if you use the Set/Get Encrypt String action on string array. Encrypt strings(and/or converted data to strings) into string array then save array.

Note: Tested on Unity 4.x only and this is not a replacement to XML / JSON. PlayerPrefsX isn't intended to turn PlayerPrefs into a database system. If you have large amounts of data, you should use standard disk IO functions instead.

Note: Need to save 300+ keys then use http://hutonggames.com/playmakerforum/index.php?topic=10081.0

Update: all actions + updates are on ecosystem or https://snipt.net/dudebxl/ (https://snipt.net/dudebxl/)

Hope it helps someone as much as it has helped me..
Title: Re: Saving Array to PlayerPrefs
Post by: mdotstrange on May 14, 2015, 10:37:55 PM
I used this in my game today- works great- thanks so much for this and all your actions  :)
Title: Re: Saving Array to PlayerPrefs
Post by: jeanfabre on June 03, 2015, 03:02:19 AM
Hi,

 yeah, this is great to see all the work you are putting in. Keep dreaming! :)

 Bye,

 Jean
Title: Re: Saving Array to PlayerPrefs
Post by: miketolsa on September 01, 2015, 07:46:05 AM
some how I am getting playerprefx not in current context error everytime I am trying to get the unity package installed in current project using unity 5.1.1f1 with latest playmaker & arraymaker installed .....
Title: Re: Saving Array to PlayerPrefs
Post by: dudebxl on September 02, 2015, 06:52:00 AM
Hi,

Can you give a break down of how u install everything.. Here is how u should do it.. Install arraymaker then install playprefs x then these actions.. When do u get the error?
Title: Re: Saving Array to PlayerPrefs
Post by: szomaza on February 10, 2019, 08:26:39 AM
Thank you dudebxl for this, just what I was looking for now, but I have a problem I can't seem to figure out.

The PlayerPrefsx Set Array List works once (goes to Finished Event) but then the next time I use it, trying to update the values in player prefs, it goes to Failure Event with the following error message:

Code: [Select]
Index is less than 0 or more than or equal to the list count.
Parameter name: index
10
UnityEngine.Debug:Log(Object)
HutongGames.PlayMaker.Actions.PlayerPrefsxSetArrayList:GetItemAtIndex() (at Assets/PlayMaker Custom Actions/Array PlayerPrefsX/PlayerPrefsxSetArrayList.cs:161)
HutongGames.PlayMaker.Actions.PlayerPrefsxSetArrayList:OnEnter() (at Assets/PlayMaker Custom Actions/Array PlayerPrefsX/PlayerPrefsxSetArrayList.cs:85)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2768)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2715)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2643)
HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2784)
HutongGames.PlayMaker.Fsm:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1995)
PlayMakerFSM:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:579)

Any idea what could be causing this?
Title: Re: Saving Array to PlayerPrefs
Post by: szomaza on February 22, 2019, 11:36:54 AM
The error message sounds like it does not restart from index 0 when I use it the 2nd time.
(my array is 10 long)
Code: [Select]
Index is less than 0 or more than or equal to the list count.
Parameter name: index
10

How do I get it to always restart from index 0?
Is that even how it should work?

Please share any idea I should try to figure this out.

Thanks,
szomaza

Title: Re: Saving Array to PlayerPrefs
Post by: jeanfabre on March 05, 2019, 12:29:35 AM
Hi,

 this action needs a reset option like we did on other similar iterating actions.

This is blind coding, but try the action attached. Add a state prior to your state with that action, and set a bool variable called  for example "Reset iterator" to true, then reference in that save array action this bool variable. the action will check it and if true will reset itself so you can iterate once again from the beginning.

if that doesn't work, can you send me a simple project that I can test and debug?

Title: Re: Saving Array to PlayerPrefs
Post by: szomaza on March 09, 2019, 03:20:09 AM
Thank you Jean!

It works perfectly now with the reset option: Using it again and again in the same state, it never goes to failure event now, but saves the values correctly to playerprefs.