playMaker

Author Topic: Save actions from unity live lecture  (Read 4290 times)

dougbello

  • Playmaker Newbie
  • *
  • Posts: 32
Save actions from unity live lecture
« on: July 21, 2015, 11:07:10 PM »
Hello guys,

I was wondering if any good soul would be able to convert this action in a playmaker script for us to save our variables in unity.

I saw this tutorial here https://unity3d.com/pt/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

Then watched it pausing and manage to copy the commands, so maybe its easier for someone to make it playmaker friendly.

They say that its a lot safer then playerprefs, so I think we should use it...

I think someone with little coding experience could turn it into playmaker with fields that we can put our own variables.

Someone can help?

Thanks a lot.
Doug.

update: I don't even know how to save a script in monodevelop, I think i've meesed it up, so I'm copying the commands here:

using System;
using UnityEngine;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public class GameControl : MonoBehaviour {

   public static GameControl control;


   public float health;
   public float experience;


   void Awake () {

   }

   public void Save()
   {
      BinaryFormatter bf = new BinaryFormatter();
      FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");

      PlayerData data = new PlayerData ();
      data.health = health;
      data.experience = experience;

      bf.Serialize (file, data);
      file.Close ();

   }


   public void Load()
   {
      if(File.Exists(Application.persistentDataPath + "/playerInfo.dat");
      {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
         PlayerData data = (PlayerData)bf.Deserialize(file);

         health = data.health;
         experience = data.experience;

      }
   }

   [Serializable]
   class PlayerData
      {
         public float health;
         public float experience;
      }
« Last Edit: July 21, 2015, 11:10:09 PM by dougbello »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Save actions from unity live lecture
« Reply #1 on: July 22, 2015, 06:18:03 AM »
I would love to help.. But i dont have my computer. If nobody helps then try my actions: playerprefsQ

It can be used for a saving large amount of data including arrays and it is quicker than the normal playerprefs. Search forum for it..

When i get my computer back.. I will convert the script but it might be in two or three months from now..
« Last Edit: July 22, 2015, 06:19:52 AM by dudebxl »

dougbello

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Save actions from unity live lecture
« Reply #2 on: July 23, 2015, 10:07:45 AM »
Hey dudebxl, thanks for the answer.

I hope someone can manage to do it, because I really cannot code myself.

I tought it was an easy code to port, once is already written and so few lines.

If someone points me a tutorial, I could try myself. (I saw the wizard but no idea how it works)

Thanks againd and I hope you have your computer soon, I would die if I had to stay 3 months away without mine.
Doug.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Save actions from unity live lecture
« Reply #3 on: July 23, 2015, 01:28:41 PM »
Yeah thx   :)

Like I said, if nothing happens, use my playerprefsQ actions. It is build around a similar principle as your data. It will save all your data into a .txt file and all the actions are available already (int, float, string, arrays, etc).

here is the link: http://hutonggames.com/playmakerforum/index.php?topic=10081.0

but honestly for two floats, I don't see the point of using anything except playerprefs - speed becomes an issue after 200+ playerprefs keys

anyway good luck dude  8)


dougbello

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Save actions from unity live lecture
« Reply #4 on: July 23, 2015, 01:35:48 PM »
Hi dudebxl,

I see your point... I really don't have many variables to save it will be around 5.

My concern was if it is safe to save them using playerprefs... once the guy in that tutorial said its "unsafe".

I just don't want users to lose their progress in my game... by the way will be for mobile.

But if you guys think playerprefs are safe enought for it, I would love to use it, once its a lot easier too.

Thanks again.
Doug.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Save actions from unity live lecture
« Reply #5 on: July 23, 2015, 01:52:38 PM »
Hi,

I think what he means by unsafe: a user can change his score (or any other data).. or that when user deletes the game on mobile he also deletes playerprefs.. or something like that..

if you need to protect your data use this (also by me  :D):

http://hutonggames.com/playmakerforum/index.php?topic=10522.0
http://hutonggames.com/playmakerforum/index.php?topic=10523.0
http://hutonggames.com/playmakerforum/index.php?topic=10524.0
http://hutonggames.com/playmakerforum/index.php?topic=10526.0

It is very simple to use and if you use a good password (note: for extra secure, use part of device ID code or any other unique ID to build your password when the game first starts making the password unique per device but only recommended in extreme case and for super secure data then use proper encryption tools), your data is safe. If they try to hack the playerperfs, the data will reset to 0 or 'blank' automatically by my actions..

hope it helps..