13 Replies - 425 Views - Last Post: 18 July 2017 - 02:06 PM Rate Topic: -----

#1 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 03:57 PM

Would like to be able to serialize a simple save outputting variables 1 per line in plain txt or some other type of file. Encryption is not needed. Could someone help with just the base code for this, I can handle the variables. I will have them setup like this
[Serializable]
    public struct GameSaveData
    {
        // Player Stat Variables
        // Variables below.
    }

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with save and load. XNA 4.0 Game Application

#2 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 04:16 PM

Also should add that I do not have or know how to put a text box for typing input IE for saving the game file/loading. Is it possible to do this as an external prompt/popup dialog from the OS?

This post has been edited by Snaef98: 17 July 2017 - 04:16 PM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 05:16 PM

Why not use streamwriter/streamreader to write to a file? Assuming you keep the format consistent it shouldn't be a problem.
Was This Post Helpful? 0
  • +
  • -

#4 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 05:18 PM

Will that work for a non console app?
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 05:44 PM

I don't see why it wouldn't. Pretty sure I remember doing that with XNA some years back.
Was This Post Helpful? 0
  • +
  • -

#6 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 07:32 PM

I used this with C++ console app years ago. I don't know how to set it up and I cant seem to get the code from the MSDN to work. Any chance you or someone is willing to provide it? Just the code, with where to put it and ill provide my own variables ;)
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 07:59 PM

It's streamwriter. Pretty basic stuff. What have you tried?

https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

#8 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 08:01 PM

The sample given by MSDN. but its got errors about device does not exist in current context. it uses xbox contols too and its programmed for keyboard.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 08:04 PM

No clue what that's all supposed to mean.
Was This Post Helpful? 0
  • +
  • -

#10 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 08:09 PM

looking for clear instructions like this https://gavindraper....e-state-in-xna/

Not sure if this example works for XNA 4.0 though. Clearing out the bad code gonna try that.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 08:12 PM

Odd. Serializing a class of information is fairly larger, more complex, step than say using streamwriter. So it goes.
Was This Post Helpful? 0
  • +
  • -

#12 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 08:58 PM

I just need to save a list of variables to a text file line by line. Could you please help me with the code? This code compiles fine but it doesn't do anything when its run doesn't even freeze the game. I cant find the save file lol

Well I found it, it did create a save file:
<?xml version="1.0"?>
<SaveGame xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <PlayerPosition>
    <X>0</X>
    <Y>0</Y>
  </PlayerPosition>
</SaveGame> 


But I don't know how to make it save more. or other types of data arg its not like the old streamwriter I used

Well it seems to be working at least when it comes to Vectors and Strings gonna test out int and bool and then get the load code going if all goes well I will have save/load ;)
Was This Post Helpful? 0
  • +
  • -

#13 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 17 July 2017 - 09:53 PM

Works able to save and load data to .txt the layout is xml but that's fine. It works so far. ill keep you guys updated after I refactor my variables and organize all my save data.
Was This Post Helpful? 0
  • +
  • -

#14 Snaef98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 11-July 17

Re: Need help with save and load. XNA 4.0 Game Application

Posted 18 July 2017 - 02:06 PM

Well the entire feature is fully working properly and implemented. Generates a save of about 20kb in XML. Works good. Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1