User/game statistics?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

User/game statistics?

#1 Post by usul »

Is it possible to save data to a text file, an xml or data base for statistical use?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: User/game statistics?

#2 Post by Jake »

usul wrote:Is it possible to save data to a text file, an xml or data base for statistical use?
I'm pretty sure Ren'Py itself doesn't have any functionality for this past the persistent-data stuff, which isn't really the same, but Python has I/O, XML parsing and various other data persistence modules. There are also various Python ODBC wrappers available, but that's probably not such a great idea on a Ren'Py game.
Server error: user 'Jake' not found

nibl
Regular
Posts: 36
Joined: Sun Feb 14, 2010 2:59 am
Projects: Lit - Literacy Teaching Game
Contact:

Re: User/game statistics?

#3 Post by nibl »

Parsing XML creates quite a bit of overhead and programming complexity. I've used both and would say use plain text. It's amazing what you can do and how much faster and simpler it is. I've also used sqlite as a small desktop cross-platform, solution, but it's not necessary unless you have complex table joins...which is unlikely for a game.

Keep it simple, just slurp in a line of data with some Python and split on a delimiter:

key1=value1
key2=value2
http://litnow.org
Open Source Literacy Project

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: User/game statistics?

#4 Post by Jake »

nibl wrote:Parsing XML creates quite a bit of overhead and programming complexity.
. . .

This is pretty much entirely down to the library you're using. XML is generally more robust than plain-text (more resilient to a semi-knowledgeable user fiddling with it, and less likely to have hidden errors, where the program doesn't break but also doesn't do what it's supposed to because of mis-interpreted data) and unless you're writing out/reading data with a completely known shape and length, a half-decent XML library provides for you all the functionality you'll have to hack together by hand for your text-file data IO.

Text files (e.g. INI files) are fine for storing completely 'flat' data (no repeated records, no nested records) but after that XML (with a decent library) is generally a lot easier to code. Having written software that reads and writes from plain text files, binary files and XML files, I would say XML is generally one of the more friendly to program... bearing in mind that nobody in this day and age should have to write their own XML parser.
nibl wrote: Keep it simple, just slurp in a line of data with some Python and split on a delimiter
This is fine so long as you can absolutely guarantee that the key or the data will never contain your delimiter, and has a completely flat shape. I'd be tempted to store data like that in an XML file anyway, just because there are libraries I can use which mean I don't have to worry about questions like that.



The one area XML parsing can fall down on is performance, if you read in the entire DOM for a large document you can take up a lot of RAM (workaroundable in a lot of libraries by just not doing that and reading the data bit by bit), and it's obviously a little slower to insert new records, so if performance is absolutely critical and you're inserting a lot of data you may want to do something different. But generally speaking, these concerns are very minor on modern equipment.
Server error: user 'Jake' not found

Post Reply

Who is online

Users browsing this forum: Yone28