Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, Aku_Aku, 1 invisible), 579 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Lots of little files #435486
01/08/14 13:15
01/08/14 13:15
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
I am creating a sort of in-game database, which will store information collected by the player. The player will also be able to write notes and change information during game-play.

In order to accomplish this I'm using a sequence of file_str_read and file_str_write commands. For a lot of the information, I can just write it in one big txt file, and access it when I need to . However, for any strings that the player gets to change, or rewrite, I create a separate file, with a unique filename, for that one piece of data.

I am concerned about creating so many different, individual files, but should I be? Is there anything wrong with making lots of files, possibly hundreds or thousands of small text files?

If so, my question is this: Is there a way to rewrite data in a file without messing up the other information stored in the same file?

Re: Lots of little files [Re: Dooley] #435488
01/08/14 13:37
01/08/14 13:37
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline
Member
TehV  Offline
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Ideally you should try storing all your data in one large file rather than many small ones. A lot of small files take up more disk space than a single large one with the same content, and a lot of small files look messy.
You could read all of the file into a string, read the value you want to change, do a search&replace of that value and replace it with the new value and write the modified string back into the file. To help you not get the correct value you should create a specific format for storing your data (try writing an XML file, for example).

Is it not possible for you to use the game_save() functions that are already included in Gamestudio?

Last edited by TehV; 01/08/14 13:39.
Re: Lots of little files [Re: TehV] #435501
01/08/14 15:24
01/08/14 15:24
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Use something like sqlite.


3333333333
Re: Lots of little files [Re: Dooley] #435517
01/08/14 17:21
01/08/14 17:21
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: Dooley
I am concerned about creating so many different, individual files, but should I be? Is there anything wrong with making lots of files, possibly hundreds or thousands of small text files?
No. If it works for you do it this way.
Quote:
If so, my question is this: Is there a way to rewrite data in a file without messing up the other information stored in the same file?
Only as long as the length of the data sets to be written is known and does not change. If you have changing data you need an extra layer of complexity, like using JSON, XML or something like that. As long as your first idea works out I wouldn't do that.


Always learn from history, to be sure you make the same mistakes again...
Re: Lots of little files [Re: Uhrwerk] #435545
01/09/14 00:14
01/09/14 00:14
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Thanks for the advice! I think I will keep it the way it is for now. If it becomes a problem, I will revisit again later.

Re: Lots of little files [Re: Dooley] #435546
01/09/14 00:17
01/09/14 00:17
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
I am using game_save for saving levels. however this is a sort of database of info that the player collects during the game. The information needs to be accessible outside of an individual level, and this seemed the best way to accomplish that.

Re: Lots of little files [Re: Dooley] #435565
01/09/14 09:12
01/09/14 09:12
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline
Expert
fogman  Offline
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany


no science involved
Re: Lots of little files [Re: fogman] #435599
01/09/14 14:22
01/09/14 14:22
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline
Member
TehV  Offline
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
If you use info variables (variables that have their name end with _i) then you can easily use game_save to store your database. All you need to do is give SV_INFO as the mode:
Code:
game_save("database",0,SV_INFO);



To save your level, you give SV_ALL-SV_INFO as the mode:
Code:
game_save("mylevel",0,SV_ALL-SV_INFO);



You then load your info save file back right when you start the game. Because game_load only changes things that were actually saved in the file you're loading, you can easily save and load your info (database) file at any time.
I assume your database has an undefined size, so you could define an array that has a length of a few thousand values like so:

Code:
var mydatabase_i[65535];



If you happen to use up all 65'535 values in that array, then you can always increase the amount of items in it.


Why spend so much time writing into custom file formats when you can just use what lite-C already gives you?

Last edited by TehV; 01/09/14 14:23.
Re: Lots of little files [Re: TehV] #435600
01/09/14 14:31
01/09/14 14:31
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Because game_save/load does have a lot of limitations to the point that it simply gets unusable once you create anything (non-entity related) dynamically (using it only for info variables may work though). If you write your own stuff you have full control over it.

Although I'm a fan of global variables and arrays you shouldn't create and write such huge arrays in your script, always try to keep them low and reasonable.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Lots of little files [Re: Superku] #435613
01/09/14 16:32
01/09/14 16:32
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
There's no bad way to do this, because the number of files wont harm the system, unless it goes to extreme limits laugh I've had 100's of 1000's of files at some points.

What I did in my latest project is to use a database for information, storing 100 000's entries and communicating through a PHP file (for security) that connects the database and to the application. This is in case you'r going Multiplayer.
Otherwise, dont worry, small text files are OK.

And, it should be possible to change only parts of those files... I didnt really understand what stops you?


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1