Page MenuHomeFeedback Tracker

missionProfileNamespace Seems to Load Only Once
New, NormalPublic

Description

I have been developing a framework to use the missionProfileNamespace as a poor-man's database, as it were, but it only seems to load once during server uptime. Variables will save well-enough, but if I restart the mission, the init seems to be reading variables from an older version of the missionProfileNamespace. If I restart the server, then it seems like the new variables are read.When I switched to the profileNamespace, I no longer have this issue.

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Linux
Operating System Version
Debian 5.10.179-1
Category
Dedicated Server
Steps To Reproduce
  1. Start server
  2. Run mission
  3. Variables are read from vers1 missionProfileNamespace
  4. Let mission save to missionProfileNamespace, now vers 2
  5. Restart mission
  6. Variables appear to be read from vers 1 missionProfileNamespace, instead of vers 2.
  7. Restart server, without letting the mission save to vers 2 missionProfileNamespace
  8. Run mission
  9. Variables are read from vers2 missionProfileNamespace.
Additional Information

Save script I used.

/*
 * Author: Bilgecrank
 * 
 * Instantiate the crates for the mission and set an event handler to save their inventory when finished.
 *
 * Returns: True.
 *
 */

private "_inventory", "_specialInventory";
localNamespace setVariable ["_missionActive", true];
private _missionBoxes = [	gunCrate,			//0
							bulletCrate, 		//1
							launcherCrate, 		//2
							missileCrate, 		//3
							bombCrate, 			//4
							grenadeCrate,		//5
							uniformCrate, 		//6
							itemCrate, 			//7
							medicalCrate,		//8
							attachmentCrate,	//9
							radioCrate,			//10
							seahawk,			//12
							mrzr1,				//13
							mrzr2,				//14
							rhib1,				//15
							rhib2				//16
							];

// Ensure that bags are redistributed during disconnects, so no gear is lost.
addMissionEventHandler ["HandleDisconnect", {
	if (allPlayers isEqualTo []) then {
		private _getInventory = (_thisArgs select 0);
		diag_log text "PESTIS: Last player left the server, saving inventory.";
		private _boxes = [(_thisArgs select 0), true] call blg_fnc_boxToArray;
		private _specialBoxes = [[specialCrate], false] call blg_fnc_boxToArray;
		[_boxes, _specialBoxes] call blg_fnc_loadBoxes;
		missionProfileNamespace setVariable ["pestisCrateInventory", _boxes];
		missionProfileNamespace setVariable ["pestisSpecialInventory", _specialBoxes];
		saveMissionProfileNamespace;
	};
	false;
	}, [_missionBoxes]
	];

addMissionEventHandler ["MPEnded", {
	private _getInventory = (_thisArgs select 0);
	diag_log text "PESTIS: Game ended, saving inventory.";
	localNamespace setVariable ["_missionActive", false];
	private _boxes = [(_thisArgs select 0), true] call blg_fnc_boxToArray;
	private _specialBoxes = [[specialCrate], false] call blg_fnc_boxToArray;
	missionProfileNamespace setVariable ["pestisCrateInventory", _boxes];
	missionProfileNamespace setVariable ["pestisSpecialInventory", _specialBoxes];
	saveMissionProfileNamespace;
	}, [_missionBoxes]
	];

// Collect inventory from save.
_inventory = missionProfileNamespace getVariable "pestisCrateInventory";
_specialInventory = missionProfileNamespace getVariable "pestisSpecialInventory";

// Fill crates with saved inventory if available.
if (!isNil "_inventory") then {
	diag_log text "PESTIS: Initializing inventory from save.";
	if (!isNil "_specialInventory") then {
		[_inventory, _specialInventory] call blg_fnc_loadBoxes;
	} else {
		[_inventory] call blg_fnc_loadBoxes;
	};
};

// Set auto-save of all crates, only runs when players are active.
[_missionBoxes] spawn {
	params ["_missionBoxes"];
	while {sleep 300; localNamespace getVariable "_missionActive"} do {
		if !(allPlayers isEqualTo []) then {
			diag_log text "PESTIS: Auto-saving crate inventory.";
			private _boxes = [_missionBoxes, true] call blg_fnc_boxToArray;
			private _specialBoxes = [[specialCrate], false] call blg_fnc_boxToArray;
			[_boxes, _specialBoxes] call blg_fnc_loadBoxes;
			missionProfileNamespace setVariable ["pestisCrateInventory", _boxes];
			missionProfileNamespace setVariable ["pestisSpecialInventory", _specialBoxes];
			saveMissionProfileNamespace;
		};
	};
};

true;

Event Timeline

This comment was removed by BIS_fnc_KK.