Jump to content
Vandeanson

Access external file with loot arrays

Recommended Posts

Hi all,

 

I am looking for a solution or some guidance to understand how I can pull arrays of loot (e.g. weapons, gear,...) from a separate file into a .sqf file.

 

What I want to do:

 

- create a master file with arrays of items, weapons, or structures

- create scripts (e.g. LINK)that spawn loot that can access those master files

- have one single file where I can alter those arrays without having to update the arrays in each single script

 

an example for an array that is currently in each of my scripts and that I would like to export into a master file and then acces from such master file:

_itemsArray =[ "rvg_canOpener", "rvg_plasticBottlePurified", "rvg_spirit", "rvg_franta", "rvg_milk", "rvg_rice", "rvg_hose", "rvg_guttingKnife", "rvg_tire", "rvg_purificationTablets", "rvg_flare", "rvg_matches", "rvg_Geiger", "rvg_toolkit", "rvg_antiRad", "muzzle_snds_B", "muzzle_snds_L", "acc_flashlight_pistol", "optic_DMS" ];

 

Any input is very welcome;)

 

thank you and cheers

vandeanson

 

 

Share this post


Link to post
Share on other sites

if you make the _itemsArray  global you can then access it in any sqf file. to make variable global just leave out the _

like so:

 

itemsArray = ["rvg_canOpener", "rvg_plasticBottlePurified",

 

just execute the sqf where itemsArray is before the other sqf files

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
27 minutes ago, gc8 said:

if you make the _itemsArray  global you can then access it in any sqf file. to make variable global just leave out the _

like so:

 


itemsArray = ["rvg_canOpener", "rvg_plasticBottlePurified",

 

just execute the sqf where itemsArray is before the other sqf files

so i could have a sqf with the above in it, and in the second sqf, that will be executes afterwards, my reference to the array will be as itemArray instead of _itemArray right?

Share this post


Link to post
Share on other sites
13 minutes ago, Vandeanson said:

so i could have a sqf with the above in it, and in the second sqf, that will be executes afterwards, my reference to the array will be as itemArray instead of _itemArray right?

 

correct. itemArray is your global variable

  • Thanks 1

Share this post


Link to post
Share on other sites

thank you mate, much appreciated;) i will test it and confirm back once i get to it! cheers!

Share this post


Link to post
Share on other sites

Some other methods/commands:

_array = call compile preprocessFileLineNumbers "file.sqf";
// file.sqf:
[item1,item2,...]

#include "file.sqf"
// file.sqf:
_array = [item1,item2,...];

 

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, 7erra said:

Some other methods/commands:


_array = call compile preprocessFileLineNumbers "file.sqf";
// file.sqf:
[item1,item2,...]

#include "file.sqf"
// file.sqf:
_array = [item1,item2,...];

 

cheers mate, is this to be put into description.ext?

Share this post


Link to post
Share on other sites

Both commands can be used in .sqf files. description.ext doesn't use the sqf scripting language but a C-like one. There are special commands for files like that: https://community.bistudio.com/wiki/PreProcessor_Commands

I'm going to break down the commands from above for better understanding:

_array = call compile preprocessFileLineNumbers "file.sqf";

"file.sqf": Insert the path relative to the mission.sqm. 

preprocessFileLineNumbers: Tells the engine to load the content of the file as a "STRING".

compile: Converts the "STRING" to {CODE}

call: Executes the given {CODE} and returns the last returned variable, in this case the array

 

#include "file.sqf"

#include is a preprocessor command. It essentially replaces the command with the content of file.sqf.

eg.

file.sqf:

_myArray = [1,2,3];

script.sqf:

#include "file.sqf"
systemchat str _myArray;

Same as:

_myArray = [1,2,3];
systemchat str _myArray;

 

  • Thanks 2

Share this post


Link to post
Share on other sites

thank you @7erra!

i will check it out next occasion, thanks for your efforts to explain the details above:)

Share this post


Link to post
Share on other sites

@7erra & @gc8

thank you both, i played around with the suggested solutions and it works as desired;)

 

i am currently using the "#inlude file.sqf" variant.

cheers vandeanson

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

×