First of all I would like to express my gratitude to Matthew for his continuous support. Now I also know who he is . Thanks mate, you are the best!
Ok. This new extension is not meant to be used on a game server or client because of security issues with writing files, it is merely a tool so that those of you who want to save some data to a file from Arma can do so. And to make sure no harm is done if someone uses it as not intended, I added safety feature – you cannot overwrite existing files, and hence you cannot append to existing files, sorry about that. You will be able to create new files in existing folders and this should be enough for variety of applications.
I was mainly thinking of the ability for Arma enthusiasts to dump some useful data in a file, like objects composition in mission.sqm like format or other format, or saving inventory setup as a ready to go script or… well you get the idea. It just writes a string of text into a file. The only feature I added was to interpret \n in strings as a new line. So “line1\nline2″ will be written as:
The extension will always return with a text message. If everything is alright it will return with “OK”. If for some reason it could not make file, it will return with error message. So it is up to you how you would want to check the success of the operation.
The extension accepts the following format: <filepath>|<data>, for example:
However if you are dumping large strings of data, you might want to avoid using format command as it has a limit. It is safer to use string addition:
So in the rawest form the use of extension will look like this:
This will create myFile.txt in the same folder as the extension and write into it:
Instead of relative path you can also use absolute path to your file, for example “C:\Users\KK\Desktop\myFile.txt“.
I have also written a function, which I think should make it a little bit more convenient to temporary stack lines in a variable and then write them in one go. Here is the code:
Basically if you send TEXT to the function it treats it as a line and makes a stack. If you send it a STRING it will interpret it as filepath and will call extension with the data stored in the stack, after which it will empty the stack. Here is an example of the use, should give you some ideas:
Resulting file would look like this:
EDIT: I reviewed security arrangements with file making and added ability to overwrite the last file you wrote in successfully. This is available in v1.1. The version can be found by using ABOUT command:
hint (“make_file” callExtension “ABOUT”);
EDIT: Well, I have reviewed security arrangements even further and upgraded the .dll to v1.5. In case someone would like to permanently keep the .dll in Arma 3 directory, any call to make_file with new filepath will trigger a modal message box prompting user to confirm the file write operation. If user cancels the request he will have a choice to further block all file write requests if necessary. I added this so that if in an unfortunate case of someone trying to abuse this in multiplayer this will stop possible griefing. Once blocked, the only way to reenable .dll functionality would be by restarting the game.
Because of this 2 more error messages are added:
- “USER CANCELLED” – when user presses “Cancel” button
- “USER BLOCKED” – when .dll is blocked