# Ruby "Save Game" function

**URL:** <https://www.ruby-forum.com/t/ruby-save-game-function/183525>\
**Category:** Ruby\
**Created:** [February 16, 2010, 4:32am UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525 "2010-02-16T04:32:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [February 16, 2010, 4:32am UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525/1 "2010-02-16T04:32:50Z")

</div>

Hello!

I am currently working on a text-based RPG and I wanted to implement a  
function that allowed the user to save their game at any point, so that  
it could be resumed later. Of course, this would need to be complimented  
by a load function that would resume the game at that previous state.

Anybody know how I would do this? 🙂

Thank you in advance!

-SS

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [February 16, 2010, 7:07am UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525/2 "2010-02-16T07:07:18Z")

</div>

Michael B. wrote:

> I am currently working on a text-based RPG and I wanted to implement a  
> function that allowed the user to save their game at any point, so that  
> it could be resumed later. Of course, this would need to be complimented  
> by a load function that would resume the game at that previous state.

For starters, I’d suggest looking at PStore and YAML::Store.

PStore:

[http://ruby-doc.org/stdlib/libdoc/pstore/rdoc/classes/PStore.html](http://ruby-doc.org/stdlib/libdoc/pstore/rdoc/classes/PStore.html)

YAML::Store exmaple:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113207](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113207)

PStore and YAML::Store are essentially equivalent in functionality,  
the difference is PStore saves objects in Ruby’s binary marshal  
format, whereas YAML::Store saves objects in human-readable YAML  
text format. And the trade-off is that YAML is slower than marshal.

Further possibilities for key/value stores with Ruby:

[http://www.engineyard.com/blog/2009/key-value-stores-in-ruby/](http://www.engineyard.com/blog/2009/key-value-stores-in-ruby/)  
[http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-2-tokyo-cabinet/](http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-2-tokyo-cabinet/)  
[http://www.engineyard.com/blog/2009/cassandra-and-ruby-a-love-affair/](http://www.engineyard.com/blog/2009/cassandra-and-ruby-a-love-affair/)  
[http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-4-to-redis-or-not-to-redis/](http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-4-to-redis-or-not-to-redis/)  
[http://www.engineyard.com/blog/2009/mongodb-a-light-in-the-darkness-key-value-stores-part-5/](http://www.engineyard.com/blog/2009/mongodb-a-light-in-the-darkness-key-value-stores-part-5/)  
[http://www.engineyard.com/blog/2009/key-value-stores-in-ruby-the-wrap-up/](http://www.engineyard.com/blog/2009/key-value-stores-in-ruby-the-wrap-up/)

Hope this helps,

Bill

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [February 16, 2010, 11:52am UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525/3 "2010-02-16T11:52:08Z")

</div>

Bill,

Thank you for the links! It’s still a lot to chew on, but I’ll try to  
figure it all out. 😛

Best Regards,

-SS

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [February 16, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525/4 "2010-02-16T14:30:58Z")

</div>

On 16 Feb., 11:52, Michael B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Bill,
> 
> Thank you for the links! It’s still a lot to chew on, but I’ll try to  
> figure it all out. 😛
> 
> Best Regards,
> 
> ## -SS
> 
> Posted viahttp://www.ruby-forum.com/.

Hi,

you could try out MongoDB or CouchDB as well.

> **[MongoDB: The Developer Data Platform](https://www.mongodb.com/)**
>
> Get your ideas to market faster with a developer data platform built on the leading modern database. MongoDB makes working with data easy.

[http://couchdb.apache.org/](http://couchdb.apache.org/)

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [February 18, 2010, 1:21am UTC](https://www.ruby-forum.com/t/ruby-save-game-function/183525/5 "2010-02-18T01:21:23Z")

</div>

Michael B. wrote:

> Hello!
> 
> I am currently working on a text-based RPG and I wanted to implement a  
> function that allowed the user to save their game at any point, so that  
> it could be resumed later. Of course, this would need to be complimented  
> by a load function that would resume the game at that previous state.
> 
> Anybody know how I would do this? 🙂
> 
> Thank you in advance!
> 
> -SS

May I suggest “sequel + sqlite”? [http://sequel.rubyforge.org/](http://sequel.rubyforge.org/)
