This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gazzzah
Gazzzah wrote ...

2012/4/17

Save files

Gazzzah Gazzzah

2012/4/17

#
How does one go about saving and opening data to a file? I hope to have my scenario save scores and in game settings on local machines. I hope to achieve the following: Generate a file in a specific location if it doesn't already exist there (may have to be different depending on OS). Edit this file to store variables (most likely just integers with identification of what they are) Read this file later to access those variables again.
nccb nccb

2012/4/17

#
One easy way to do this might be to use the new storage mechanism in 2.2 once it's released. It's called PlayerData in the beta, although we're probably about to rename it for the final release. Whether that suits your needs depends on how much data you want to store. If it's just a few integers, that will be just fine.
Gazzzah Gazzzah

2012/4/18

#
Sounds interesting, can you explain that a little more? Does it store locally or on the internet? How does it work?
nccb nccb

2012/4/18

#
When running in the IDE, it stores the data locally in a file (and handles all the file-writing and file-reading for you). When you export your scenario to the greenfoot.org website, the data is stored (per-user) on our server, but you don't have to modify your code at all -- you use the same code locally and exported, and Greenfoot does the right thing in each circumstance.
You need to login to post a reply.