Home   Help Search Login Register  

Author Topic: Strange "Call Compile Loadfile" Bug  (Read 1138 times)

0 Members and 1 Guest are viewing this topic.

Strange "Call Compile Loadfile" Bug
« on: 01 Aug 2007, 08:48:42 »
I attempted to pass file names through script arguments (an array of strings) that would let the end user pass multiple files to read from.

Here's some sample code of what it may look like:

Code: [Select]
_files = _this select 0;  // an array of strings containing file names

_i = 0;
_fileCount = count _files;
_fileContents = [];
while {_i < _fileCount} do
{
    _fileContents = _fileContents + [call compile loadFile (_files select _i);];
};
player sideChat format ["%1", _fileContents];

Now, baring any typos, that's perfectly legitimate code there.  However, it appears that loadfile writes it's data in both directions.  In otherwords, after the first run through that loop, _files is loaded with the contents of the first loadfile command.

To work around it you have to do this:

Code: [Select]
_files = _this select 0;  // an array of strings containing file names

_i = 0;
_fileCount = count _files;
_fileContents = [];
while {_i < _fileCount} do
{
    _files = _this select 0;
    _fileContents = _fileContents + [call compile loadFile (_files select _i);];
};
player sideChat format ["%1", _fileContents];

In other words, reset _files every time you use it.

Edit:
Fixed a couple of mistakes in the code.  The code here is intended to to be completely cleaned up and generic just to illustrate the point, but I overlooked a couple of things on the originally posted code.
« Last Edit: 01 Aug 2007, 15:20:09 by ColonelSandersLite »
Everything I have released for ARMA can be found here.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Strange "Call Compile Loadfile" Bug
« Reply #1 on: 02 Aug 2007, 02:26:15 »
Hmm, very weird...

This was an sqf script called via execVM?

urp!