Jump to content
super-truite

Write in a file with a script

Recommended Posts

I saw a bunch of old posts about this and apparently it was not possible in previous BIS games.

What about now?

I am making a training mission with a bunch of different activities for my team and to make it less boring (for the fresh recruits who want to fight and not to train :) ) I am making a scoring system.

I Check the time you need to hit a series of targets with a weapon for instance. I would like to make the scoring system automatic (it is quite a pain in the * to update every script for each activity each time someone beats the previous score).

For this, I would need to read/write in a text file where I store the scores.

Apparently, writing in a file was not possible for security reasons but even being just able to read would already save me a lot of time.

Concrete example of what I want to do:

In a script shootingrange.sqf after the execution is finished, I obtain for instance a value _t=30;

I want to compare _t with a number t' that I read in a file stat.txt. Then if t'>_t, I want to replace t' by _t in stat.text

Share this post


Link to post
Share on other sites

I'm not at all familiar with scripting for Arma (just fairly fluent with vb.net) but, wouldn't this be better handled placing the variables into memory?

Share this post


Link to post
Share on other sites
I saw a bunch of old posts about this and apparently it was not possible in previous BIS games.

What about now?

I am making a training mission with a bunch of different activities for my team and to make it less boring (for the fresh recruits who want to fight and not to train :) ) I am making a scoring system.

I Check the time you need to hit a series of targets with a weapon for instance. I would like to make the scoring system automatic (it is quite a pain in the * to update every script for each activity each time someone beats the previous score).

For this, I would need to read/write in a text file where I store the scores.

Apparently, writing in a file was not possible for security reasons but even being just able to read would already save me a lot of time.

Concrete example of what I want to do:

In a script shootingrange.sqf after the execution is finished, I obtain for instance a value _t=30;

I want to compare _t with a number t' that I read in a file stat.txt. Then if t'>_t, I want to replace t' by _t in stat.text

If you need read/write access to something to keep track of something IG, why not use the same db method DayZ does?

Share this post


Link to post
Share on other sites

I am not familiar with Dayz, do you have a link on how they store stats?

I was just hoping that something equivalent to the class fstream in c++ would exist in sqf.

Share this post


Link to post
Share on other sites

Check out the command profileNameSpace and saveProfileNameSpace. You can use setVariable and getVariable profilenameSpace to set and retrieve variables to this namespace and then use saveProfileNameSpace to save it to file in "Documents" next to your profile called yourname.vars.Arma3AlphaProfile. Just be careful when saving as it eats a lot of compute cycles so only do it when necessary (don't use a loop to constantly save, etc.)

  • Thanks 1

Share this post


Link to post
Share on other sites

U should look up arma2net and arma2netmysqlplugin - save anything to database. Really useful tools

Share this post


Link to post
Share on other sites

I guess you want to make some kind of HiScores system, so players can beat each other scores and you want it persistent? Database will be the way to go then you can make different servers to access the same table if you ever want to expand. Look up callExtension command. You can always make your own extension if you cannot find what you are looking for.

Share this post


Link to post
Share on other sites

With all those ideas I add to make a difficult choice and pick up one :). I tried using profileNameSpace and it seems to work great for what I want (for the moment I am fine with just storing the datas in my profile. I'll look at more complicated solutions if I want to make something more ambitious later).

Here is a simple example where you have to kill a target named _rabbit (please don't call greenpeace) :

  _rabbit =  _this select 0;   
  _namespace = profileNamespace;  // defines a variable which represent the "storage unit" of your profile (where all your personal variables go). Everything is stored in myUsername.vars
_t = 0;
while{alive _rabbit} do{sleep 0.1; _t = _t +0.1;};  // give the time you take to kill the rabbit

_t0 = _namespace getvariable "recordtimerabbit";  // check the value of the recordtimerabbit in your myUsername.vars file


//if it is not yet defined (if you never played the mission), this defines _t0 to a value greater than _t :

if (isNil ("_t0")) then { 
                                   _t0 =_t+1;
                                   }; 
// shows the time it took you to kill this poor bastard and shows you the record if you didn't beat it
//if you break the record,  it saves the new value in   myUsername.vars using "saveProfileNamespace":

if(_t > _t0) then {
player sidechat format ["your time: %1 s",_t]; player sidechat format ["best time: %1 s",_t0];
                               }          
               else {
player sidechat format ["your broke the record! your time: %1 s",_t]; _namespace setvariable["recordtimerabbit",_t];saveProfileNamespace;
                             };


Edited by super-truite

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×