Forum Jump :

Author Message

piGuy  



Posts: 2
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2013-12-05 10:20        
     
I am working on a script to randomize ammobox contents. What I would like to do, and am having trouble with, is create global arrays that are basically a set of items that could possibly spawn inside the ammobox. However, I am having trouble with the creation, initialization, and access of global arrays. If anyone could help shed some light on what I'm doing wrong, I'd greatly appreciate it.
// init.sqf
// array containing the class names of each weapon included in the mission
_arAllW = 
[
	"launch_NLAW_F",
	"launch_RPG32_F",
	"srifle_EBR_F",
	...
	...
];
publicVariable "_arAllW";

// initAmmobox.sqf

private "_ab";        // ammobox variable
if (true) then
{
	_ab = _this select 0;
	clearMagazineCargo _ab;
	clearWeaponCargo _ab;
	clearItemCargo _ab;
	clearBackpackCargo _ab;
	
	// Total number of guns within an ammobox:  [1, 5]
	_nGuns = (random 5) + 1;

	// Count the number of elements contained in _arAllW
	_wCnt = count _arAllW;

	// loop runs nGuns times and computes a random index ranging from [0, _wCnt)
	// (cont) then adds the weapon using the randomly chosen index, _n, to the ammobox
	for [ {_i = 0}, {_i < _nGuns}, {_i = _i+1} ] do
	{
		_n = random _wCnt;
		_ab addWeaponCargo [ _arAllW select _n, 1];
	};

	// Add a random amount of grenades ranging from [0, 4]
	_ab addMagazineCargo["HandGrenade", random 5];
};

// code entered into the mission editor ammobox initialization field
_nul = [this] execVM "initAmmobox.sqf";
[\code]


Author Message


Posts: 1475
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#2 Posted at 2013-12-05 12:35        
     
Shouldn't it be used without an underscore and then used that way in all scripts ie arAllW = [ , publicvariable be "arAllW"; ect

I've only every done SP scripting so I could be wrong.

You could also use setvariable/getvariable

to set it
missionNamespace setVariable ["YourString",_arAllW,true];


to retrieve it
_arAllW = missionNamespace getVariable "YourString";