Game Development Community

Deleteing files from script

by Tom Perry · in Torque Game Engine · 06/29/2005 (2:02 pm) · 9 replies

Is there any way to delete files using script? I have run a few searches and came up with nothing. Is there a way to do this or is the source code the key? Thanks in advance.

#1
06/29/2005 (2:03 pm)
You can delete files using C++... tie in scripts with consolemethods.
#2
06/29/2005 (2:05 pm)
I was affraid of that lol. I have close to zero knowledge on C++ (just wading through script atm). What console methods are you refering too?
#3
06/29/2005 (2:35 pm)
Back in the day when scripting in game engines really started to take root, there was a debate whether one should implement "complete" languages, or limited ones. One school of thought held that embedded scripting languages ought not to be limited for the sake of security, because every possible feature would, at least some time be useful to developers or modders. The other school pointed out that there's an inherent safety risk with unlimited implementations. Should a computer game really be allowed to delete files as its discretion? Should it be able to send arbitrary data over the net?
I have no idea if you can or cannot delete files in torquescript. But if you can't, then you might have a hint as to why not.
#4
06/29/2005 (2:42 pm)
Tom : There is already a function in the engine for doing such, it is called dFileDelete - see platform.h

However, for security purposes (since it does no checking on what file is passed) it is not exposed to script. You could quite easily create a console function for doing this, but it would then allow anyone that writes script for your game to delete a file when they see fit.

You should note also that dFileDelete does not checking if the file is part of the resource manager directory structure either, so a file in C:\Windows would be fair game as well as one in C:\Games\YourGame\.

Hope this helps,

justin'
#5
06/29/2005 (2:55 pm)
Ah ok, i think I get it. I think I will leave the deleting function then, if it can delete other files not related to the game then it probably isnt the safest option! Plus i don't think I could write the console funtion, as I can't write C++. Thanks for replying, I could just send a msg to the user telling them that they need to delete the unwanted files manually if the want to remove them.
#6
06/30/2005 (4:10 am)
It's super easy to write a ConsoleMethod... Just go find another console method and use it as a template. There is documentation on it in the General Torque Documentation. Of course, you would want to do a check on any file name coming in to see if it is in the game directory... and that takes some syntax knowledge.

Pseudo Code (logic):
C++:
ConsoleMethod(...FileName...)
{
   // Check if it is in the game directory
     //if it is then delete it
   // return if it was deleted (true if deleted; false if not)
}

Script:
deleteFile("c:\Torque\SDK\engine\game\Player.cc");
#7
06/30/2005 (7:35 am)
Ok thanks for the info Chris. I have had a look at the documentation, looks pretty easy, like you said. I don't know any C++ syntax, but I understand the principals behind programming and scripting.
I took a look at the platform.h (what is that file extension? Why are some files .h and other .cc? See, I am a total noob lol) and found the dFileDelete function however I couldn't understand it!
Anyway, I'm not trying to delve into C++ atm, I am perfectly happy trying to learn script, C++ is the next step lol (I don't even know how to use a complier or any other what-nots to do with C++, I only managed to compile the engine due to the TBE and the docs with it!).
Thanks for the reply anyway, the re-read of the document helped me understand console methods a bit better and every little helps ;)
#8
06/30/2005 (8:34 am)
.h are header files... Which are mostly for declaring functions and classes. a .cpp file (or .cc for Torque) is a c plus plus source file. Which is generally where you put the implimentation of header (.h) files
#9
06/30/2005 (8:39 am)
Ah, thanks Chris.