Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Creating a save and load option  (Read 2163 times)
0 Members and 1 Guest are viewing this topic.
Offline Shane75776
« Posted 2009-02-23 18:19:53 »

Alright so this might sound really stupid but i am making a text based rpg in java because i like making them anyways my friend was telling me that you can make a simple save so that it saves all the variables into a text file. so what im asking is how do you do this i have literally no clue on were to start. if at al possible could someone maybe post a source code on for like a window hat pops up and you can select that text file and then load the variables that you previously saved. remember i have never done anything like saving so please if you can maybe put some comments in that would tell me what some parts of the code are doing if you decide to help me. many thanks to all that help  Smiley

Check out my Snipping Tool++ ! An advanced snippet/screenshot/text uploading tool! Meant to replace the windows snipping tool.

Check out Pixel Rain My most recent Swing based game!
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #1 - Posted 2009-02-23 20:27:25 »

ok, basicly google this "file IO in java". if you havent got the idea yet here it is.

you make a file that is named the name of the user(or the username). then in there you write wateva you want in there. so like your health, mana, level, exp, money, items, skills. and then when you load it. jsut read the file, and go ok line 1 is health, line 2 is mana.

I havent done this in java. I have done this in basic, the same concept should apply.

it may be more efficient to have a file called username+"skills", and username+"inventory" and so on.

but only do this  with the stuff that there si a lot of.


GL with the game
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #2 - Posted 2009-02-23 21:45:59 »

You should have a read of this

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Ninja


Medals: 55



« Reply #3 - Posted 2009-02-23 21:55:07 »

Abuse was faster, anyway:

There are multiple options to do this. A common way is to use Properties, where you need to put in the values.

Another option would be Serialization, which is a bit more comfortable, since you don't have to convert your variables from and to a string representation. On the downside, the written files normally aren't human readable.

If your class containing the variables follow java bean pattern (having public getter and setter methods), you can use Bean XML Serialization, which produces a human readable xml file. If you don't want to bother and are willing to use a third party library, you can use XStream, which allows very easy persistance of arbitrary java objects to xml files. Under more complex circumstances you might save your whole memory, though Smiley

There is also the Java Architexture for XML Binding, but this may be a bit of an overkill...

Mathias - I Know What [you] Did Last Summer!
Offline halfwitgoat

Junior Devvie


Projects: 2



« Reply #4 - Posted 2009-02-23 22:13:32 »

You should have a read of this
Now what's funny about that is the multiple of 10 line numbering.  Cheesy Reminds me of learning Basic on my good old speccy.

Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #5 - Posted 2009-02-23 22:42:14 »

Now what's funny about that is the multiple of 10 line numbering.  Cheesy Reminds me of learning Basic on my good old speccy.

Haha, I hadn't noticed that!

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #6 - Posted 2009-02-23 23:05:31 »

You should have a read of this

me too.

I have not done any file saving in java.

Is this way easier/better than mine?

causee if so thanks for saving me a hassle later.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-02-23 23:08:19 »

<offtopic>

Quote
Now what's funny about that is the multiple of 10 line numbering.

It's just a matter of time until we can use complex numbers there.

goto with volumetric jumps. revolution!

</offtopic>



Anyway, back on topic. I think the best to advice (as apposed to technically best) is to use property files.
 - Easy to code
 - Easy to debug (this is by far the most important reason, and should not have been point #2)
 - It doesn't instantly break down once your classfiles change (Serialization is rather bad in more than one way)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Shane75776
« Reply #8 - Posted 2009-02-24 15:07:53 »

alright im gonna try out a coupleof these

Check out my Snipping Tool++ ! An advanced snippet/screenshot/text uploading tool! Meant to replace the windows snipping tool.

Check out Pixel Rain My most recent Swing based game!
Offline Shane75776
« Reply #9 - Posted 2009-02-27 15:17:54 »

Well i tried a couple of these and looked them up and horribly failed at doing it right. So could someone post a really good sample source code for how to do this?

Check out my Snipping Tool++ ! An advanced snippet/screenshot/text uploading tool! Meant to replace the windows snipping tool.

Check out Pixel Rain My most recent Swing based game!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #10 - Posted 2009-02-27 16:45:39 »

go here: http://www.java-gaming.org/topics/saving-user-changed-variables/19768/view.html

enjoy.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (38 views)
2014-11-26 15:22:04

toopeicgaming1999 (33 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (25 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!