Deleting a file from inside the game

Started by KingMick, Fri 21/04/2006 11:01:13

Previous topic - Next topic

KingMick

This is not essential for my game but it would be nice to be able to do...

Right now my game is set up so that it can create up to 999 external files for use as pages in a journal system.  Since it is possible for a player to "rip out" pages via a special button, it would be nice to be able to delete files created with the File.WriteString command.  However I can find no way to do this.

Is it possible to delete game-created files from inside the game, or is this functionality unavailable for security?

Gilbert

Well you may try opening the file in mode eFileWrite and then just close it. It would clean the file up to 0 byte I think, isn't really neat as it won't delete the file but I think it serves its purpose at the moment.

KingMick

Okay, I guess I'll do that.  It'd be nice if I could delete the file entirely but if it's not possible, it's not possible.

BTW you and GarageGoth are both getting mentioned in the Special Thanks, for all your help with this...looks like after all my false starts I'm finally going to publish a game after all :D

DoorKnobHandle

I would advise you to change the limit of 999 pages. If the player would click repeatedly on the "new page" button and then on the "delete page" button, you'd end up having 999 empty text files in the game directoy. And really, who writes 999 pages in the game? Make it 25 or 15 depending on how much information fits on one page.

Or you take it a step further and make the journal system dynamic, which means that the game automatically analyses which files are empty and then when the user creates a new page it will first take an empty file and refill it instead of creating a new one. But that's not easy to do.

SSH

* SSH writes a game that overwrites windows with zero-length files, bwuhahahahah
12

Gilbert

Hehe Unfortunately it's claimed that you can't do this (might still be possible if you muck up some crazy path representation or using a plugin though := ):

VERSION 2.31, March 2002
- Restricted FileOpen to only allow access to files in game directory.

KingMick

Quote from: dkh on Fri 21/04/2006 11:25:47
I would advise you to change the limit of 999 pages. If the player would click repeatedly on the "new page" button and then on the "delete page" button, you'd end up having 999 empty text files in the game directoy. And really, who writes 999 pages in the game? Make it 25 or 15 depending on how much information fits on one page.

Or you take it a step further and make the journal system dynamic, which means that the game automatically analyses which files are empty and then when the user creates a new page it will first take an empty file and refill it instead of creating a new one. But that's not easy to do.

I'm one step ahead of you ;).  The journal is "intelligent"--before you can create a new page, it checks to see if the current one is blank and if it is, the journal tells you to put something on that page before you can make a new one.  If you delete a page, all the pages after the deleted one get moved "one page up" to fill the gap.

So, the only downside is that if you delete, say, 15 pages, then there will be 15 empty files at the very end of the page list.  When you hit the first "blank page" of the journal, though, it lets you go no further, and if you do create a new page (after putting something on the current blank one), it uses the first empty file rather than creating a whole new one.

So the suggestions you make are actually alreayd implemented :D.  And it is surprisingly easy to write the code for it, though it still took me a good 4 or 5 hours to do so.  I'm kind of a newbie; I'd be willing to bet most of you answering all my annoying questions could do it in less than an hour if you wanted to :).

SMF spam blocked by CleanTalk