Jump to content

Recommended Posts

Currently I'm trying to use an #include to call arrays from another file. But while testing, I think editor/debugger can't call from sub directories. If so I get |#|#includes invalid number...
But if I do it all in the Root Folder, it doesn't return an error, however it doesn't execute the script. But when the array is placed in the scripts file, it runs flawlessly. What exactly is going on here?

gearWhiteList:
 

_availableRockets = [
        "RPG7_F",
        "RPG32_HE_F",
        "RPG32_F"
];

 

 

gearRestrict:

#include "addons\gear\gearWhiteList.sqf"

_restrictedRocketsCount = (count _availableRockets) -1;
_count = 0;
_limitRockets = 1;
while {_count < _restrictedRocketsCount} do
{
    for "_x" from 0 to _restrictedRocketsCount do
    {
        _selectRockets = _availableRockets select _x;
        _countRockets = {_selectRockets == _x} count (backpackItems player);
        if (_countRockets > _limitRockets) then
        {
            for "_i" from 1 to (_countRockets - _limitRockets) do
            {
              player removeItem _selectRockets;
            };
        };
    };
    _count = _count + 1;
};

 

I've Tried a bit of everything:
 

#include "addons\gear\gearWhiteList.sqf"

#include "\addons\gear\gearWhiteList.sqf"
  
#include "..\addons\gear\gearWhiteList.sqf"
  
#include "gearWhiteList.sqf"

 

Can someone explain to me what is going on?

When I try to watch _availableRockets in the debugger nothing returns either.

Share this post


Link to post
Share on other sites

How are you calling your scrpt/function? You need to execute it with a command that supports preprocessor command, for example preprocessFileLineNumbers or execVM. See here: https://community.bistudio.com/wiki/PreProcessor_Commands

For example:

Quote

call compile preprocessfilelinenumbers "gearRestrict.sqf";

 

Supports stuff beginning with "#". 

 

If you don't want to rely on the preprocessor you can also write this:

Quote

private _availableRockets = call compile preprocessfilelinenumbers "gearWhiteList.sqf";

 

As the array in gearWhiteList.sqf is the last statement, it will be returned when it is called as a function.

 

Youtr post also misses some information on where you are storing your scripts. /addons/gear sounds like you are referencing an addon. pathes starting with a slash are considered addon pathes, while all others are mission pathes. If your script is in a mission with the subfolder "addons/gear/" your path needs to be  "addons/gear/gearWhiteList.sqf". If it is in an addon it needs to be  "addontag/pboname/gearWhiteList.sqf".

 

And as a general remark: you might want to declare your local variables private, otherweise you could run in some strange bugs that are nearly impossible to solve later in developing.

Share this post


Link to post
Share on other sites

Ahhh. Thanks, makes sense. Yeah, I'm working on a new template so everything is fresh and only using that line of code for testing. Was going to add Private later. Thanks! Works great @NeoArmageddon

  • Like 2

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

×