fnc_setData usage

  1. 8 years ago

    Hello again,

    I did read about setData and GetData on the wiki. So i did this piece of code thinking about storing and retrieving a value, 2.

    	_number = 2 ;
    	["Stored", _number] call ALiVE_fnc_setData;
    	
    	if ((["Stored"] call ALiVE_fnc_getData) == 2 ) then {
    	
    	["Good.","hint",true,true] call BIS_fnc_MP;	
    	  
    } else { ["Bad.","hint",true,true] call BIS_fnc_MP; };

    For you experienced people. It is a good way to use these functions? Is this code any good?

  2. Edited 8 years ago by SpyderBlack723

    When retrieving data from the database, there is usually a possibility that it hasn't been stored yet. To handle this, you should check if it exists before doing anything with it

    //-- Set data
    _number = 2;
    ["Stored", _number] call ALiVE_fnc_setData;
    //-- Get Data
    private ["_number"];
    _number = ["Stored"] call ALiVE_fnc_getData;
    if (isNil "_number") then {
    	//-- Data does not exists, create a default for it or skip this operation entirely
    	_number = 2;
    } else {
    	//-- Data exists
    	if (_number == 2 ) then {	
    		["Good.","hint",true,true] call BIS_fnc_MP;  
    	} else {
    		["Bad.","hint",true,true] call BIS_fnc_MP;
    	};
    };

    Hopefully there are no errors in that snippet

  3. Thank you for the answer SpyderBlack, i will take a look of this all.

  4. Tupolov

    23 Feb 2016 Administrator

    Spyder is right, data is only saved when the mission is ended, and only loaded when the mission has begun. So you setData at the end of your mission and getData at the beginning.

 

or Sign Up to reply!