playMaker

Author Topic: Saving XML proxy to playerprefs [SOLVED]  (Read 2938 times)

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Saving XML proxy to playerprefs [SOLVED]
« on: August 28, 2017, 10:38:57 AM »
Hi I am trying to test out a level editor and want to try using DataMaker to test out my data structure before using a proper save system with encryption. 

I basically want to save a scene setup (in runtime via a button in the menu) in an XML file that stores the names of prefabs, IDs, and other info.  Then when clicking "load" in the menu the XML file is used to reconstruct the prefabs in a hierarchy.

I was thinking I could test all this out using Datamaker and Arraymaker.  Is this true?

If so I am already stuck on simply trying to create a node in an XML file. :)  Can someone please show me how to use "Xml Create Node"? 

Thanks!
Matthew
« Last Edit: September 08, 2017, 09:37:22 AM by Matthew »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Trouble with "Xml Create Node" Action
« Reply #1 on: August 29, 2017, 03:58:10 AM »
Hi,
Maybe this tutorial might help i believe on part 3 but i am not sure its been a while since i made this videos and also been a while since using datamaker :)

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Trouble with "Xml Create Node" Action
« Reply #2 on: August 30, 2017, 09:38:36 AM »
Thanks!  I was able to add a node in the proxy but how do I save the new proxy to the XML file in runtime?  I see a button to save in the inspector (save back to text asset file) but I need to save in runtime.  That way I can save, close the game and reference the XML file later in the game to rebuild the scene (I'm making a level editor).   I know this is not a proper save system but it will help me debug until I learn how to create a proper save system for my game.

Thanks for your help!
Matthew
« Last Edit: August 30, 2017, 10:49:05 AM by Matthew »

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Trouble with "Xml Create Node" Action
« Reply #3 on: September 01, 2017, 09:38:39 AM »
Can anybody help with this question?  How do I write to an XML file using Datamaker during runtime?

Thanks!
Matthew

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trouble with "Xml Create Node" Action
« Reply #4 on: September 05, 2017, 03:06:29 AM »
Hi,

 you should save the xml in the PlayerPrefs, that's the best way and most reliable way across all platforms.

 Have you tried that?

 Bye,

 Jean

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Trouble with "Xml Create Node" Action
« Reply #5 on: September 05, 2017, 11:49:07 AM »
In my level editor I need to save arrays of arrays that are used to build prefab hierarchies.  Is this a job playerprefs can handle? If so how do I store an XML file into playerprefs?

I know I need to just get Easy Save but wanted to try a solution that was free.  :)

Matthew

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trouble with "Xml Create Node" Action
« Reply #6 on: September 06, 2017, 04:48:39 AM »
Hi,

PlayerPrefs only saves ints, bool, floats and strings, so in theory yes, it can if you save your nested arrays in json or xml or custom format, the key here is the build the serializer and deserializer to save your nested arrays as string and back.

you store an xml ( not a file, but an xml document, which only leaves in the memory), but first saving it as a string, and you take this string and save it in the playerprefs.

please get this package: https://github.com/jeanfabre/PlayMakerCustomActions_U4/blob/master/PlayMaker/Ecosystem/Custom%20Packages/DataMaker/DataMaker_Samples.unitypackage?raw=true

 create a fresh new project just for this, install PlayMaker and DataMaker and import the package above. you'll have many examples, including XmlLoadSave.unity which is a quick sample showing you how to add messages to an xml and save it int he player prefs automatically, which then when you start the scene again will get that xml from the player prefs if it exists.

 Let me know how it goes.

 Bye,

 Jean

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Trouble with "Xml Create Node" Action
« Reply #7 on: September 06, 2017, 07:40:44 AM »
Cool!  Thanks So much Jean! I'll take a look at the project.

Matthew

Matthew

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Trouble with "Xml Create Node" Action
« Reply #8 on: September 06, 2017, 08:47:11 PM »
Jean, I have studied your example and I now understand how to edit XML, save as a string and store in playerprefs. 

However, the XML file I am building requires me to dynamically create nodes and nest other nodes beneath them.  For example, based on the number of prefabs saved in the scene I will need to create nodes for each prefab and corresponding parent nodes for each prefab that have varying child nodes. 

Here is an example of what I need to do:

Quote
<Level1>
<Robots>
<Robby> Robby, X,Y,Z, </Robby>
<Tom> Tom, X,Y,Z,  </Tom>
</Robots>
<Robby>
      Blah
           blah
               blah
</Robby>
<Tom>
          Blah
                blah
</Tom>
</Level1>


So my problem is I do not see an action for creating an "open node" to allow me to insert nested data under a newly created node (and also close the node).  I can not pre-define the XML structure since I do not know how many prefabs will be in the scene when saved. 

Am I missing something?  Or am I setting up my XML code wrong?

Thanks!
Matthew
« Last Edit: September 06, 2017, 08:50:56 PM by Matthew »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trouble with "Xml Create Node" Action
« Reply #9 on: September 07, 2017, 05:14:10 AM »
Hi,

 every node is open, you can add a node to another node, to any other node.

your xml is not clear enough for me to make good suggestions, can you explain exactly what blah is and how i fits. That's the beauty of XML, it's plain english, so the more explicit everything is, the easier it is to work with and understand it for third parties like me.

but here's a possible approach:

Code: [Select]
<Level1>
    <Robots>
        <Robot name="Robby">
            <Position>x,y,z</Position>
        </Robot>
       <Robot name="Tom">
             <Position>x,y,z</Position>
       </Robot>
    </Robots>
   
    <Robby>
        <node>
            <content>Blah</content>
             <node>
                <content>Blah</content>
                 <node>
                    <content>Blah</content>
                </node>
            </node>
        </node>
    </Robby>
    <Tom>
        <node>
            <content>Blah</content>
             <node>
                <content>Blah</content>
                 <node>
                    <content>Blah</content>
                </node>
            </node>
        </node>
    </Tom>
</Level1>


note that instead of having a Robot node called "Robby" I went for a generic node that will be for every robot and then added an attribute "name", that's a better approach, if your robots will have unknown names ( if the user name robot by himself for example).

 so make sure you read on xml structuring before diving too deep, it's important to realize what are the possibilities for formating and structuring within XML before starting. there is not that much, only few rules and you are set.

 Bye,

 jean