Jump to content
pierremgi

[solved] setvariable to logic module from 3den

Recommended Posts

Hi all,

I'm stuck with variables, trying to set them in a custom module to make them work in preview.

My module is fine. it is set to:  is3den = 1 , so my function module looks like:

 

_mode = param [0,"",[""]];
_input = param [1,[],[[]]];

switch _mode do {
    case "init": {
        _logic = _input param [0,objNull,[objNull]];
        _activated = _input param [1,true,[true]];

        if (_activated) then {
        hint str [_logic getVariable "defaultVeh",_logic getVariable "defaultHelo"];
        };

    };

    case "connectionChanged3DEN": {
        _logic = _input param [0,objNull,[objNull]];
        _connects = get3DENConnections _logic apply {_x select 1};
            _objects = all3DENEntities select 0 select {_x isKindOf "helicopter" or _x isKindOf "landVehicle"};
            _objectsLogic = _objects  select {_x in _connects};

            systemChat str [_objectsLogic,_objects];
      
            _helos = +(_objectsLogic select {_x isKindOf "helicopter"});
            _vehs = +(_objectsLogic select {_x isKindOf "landVehicle"});
             _heloString = str (_helos apply {typeOf _x});
             _vehString = str (_vehs apply {typeOf _x});
             _logic setVariable ["defaultHelo",_heloString];
             _logic setVariable ["defaultVeh",_vehString];

    }
};
true

 

 

 

The aim is to catch the helos and cars linked to the module, during 3den, then use their classes as reference during game (scripts).

Everything work fine while I'm in editor. SystemChat is updated with the links as intended,

the checks on console:

(all3DENEntities select 3 select 0) getVariable "defaultVeh"

and

(all3DENEntities select 3 select 0) getVariable "defaultHelo"

are OK. I get my helo and car classes along with connections.

 

The problem is these variables are not persistent when I run preview, returning [<objNull>,<objNull>]

 

I can't find what is wrong and how I could succeed in this setting.

Thanks

 

 

Share this post


Link to post
Share on other sites

You cannot setVariable inside the editor and have it preserve across preview/mission.

 

Either...

  • Retrieve your connections at runtime, instead of in the editor

Or

  • Create an attribute for your module and store types in there, where the attributes code populates setVariable at runtime. Which is a STRING representation of an array and also has the added benefit of allowing the user to add types without connection, much like you can supply vehicles for the SupportProvider_Virtual_Drop module in its "Vehicle Types" attribute.
    Spoiler

    Something like...

    
    
    class CfgVehicles
    {
    	class MyModule // Your entity class
    	{
    		class Attributes // Entity attributes have no categories, they are all defined directly in class Attributes
    		{
    			class AllowedVehicles
    			{
    				//--- Mandatory properties
    				displayName = "Allowed Vehicles"; // Name assigned to UI control class Title
    				tooltip = "Allowed vehicles"; // Tooltip assigned to UI control class Title
    				property = "allowedVehicles"; // Unique config property name saved in SQM
    				control = "Edit"; // UI control base class displayed in Edit Attributes window, points to Cfg3DEN >> Attributes
    
    				// Expression called when applying the attribute in Eden and at the scenario start
    				// The expression is called twice - first for data validation, and second for actual saving
    				// Entity is passed as _this, value is passed as _value
    				// %s is replaced by attribute config name. It can be used only once in the expression
    				// In MP scenario, the expression is called only on server.
    				expression = "_this setVariable ['%s',call compile _value];";
    
    				// Expression called when custom property is undefined yet (i.e., when setting the attribute for the first time)
    				// Entity is passed as _this
    				// Returned value is the default value
    				// Used when no value is returned, or when it's of other type than NUMBER, STRING or ARRAY
    				// Custom attributes of logic entities (e.g., modules) are saved always, even when they have default value
    				defaultValue = "[]";
    
    				//--- Optional properties
    				unique = 0; // When 1, only one entity of the type can have the value in the mission (used for example for variable names or player control)
    				validate = "none"; // Validate the value before saving. Can be "none", "expression", "condition", "number" or "variable"
    				condition = "logicModule"; // Condition for attribute to appear (see the table below)
    				typeName = "STRING"; // Defines data type of saved value, can be STRING, NUMBER or BOOL. Used only when control is "Combo", "Edit" or their variants
    			};
    		};
    	};
    };
    
    
    //module function
    _mode = param [0,"",[""]];
    _input = param [1,[],[[]]];
    
    switch _mode do {
        case "init": {
            _logic = _input param [0,objNull,[objNull]];
            _activated = _input param [1,true,[true]];
    
            if (_activated) then {
            	_vehicles = _logic getVariable[ "allowedVehicles", [] ];
            	_helos = _vehicles select { _x isKindOf "Helicopter" };
            	_landVehicles = _vehicles select { _x isKindOf "LandVehicle" };
            	hint format[ "Helos: %1/nLandVehicles: %2", _helos, _landVehicles ];
            };
        };
    	case "connectionChanged3DEN": {
    		_logic = _input param [0,objNull,[objNull]];
    			
    		//Get current items
    		_classes = call compile ( _logic get3DENAttribute "allowedVehicles" ) apply{ toLower _x };
    		//Get all connected vehicles ( of type ) 
    		_connected = get3DENConnections _logic apply{ toLower typeOf ( _x select 1 ) };
    		//Add any that are not already present
    		{
    			private _nul = _classes pushBackUnique _x;
    		}forEach _connected;
    		//Get configname so that text is not all lower case
    		_classes = _classes apply{ configName ( configFile >> "CfgVehicles" >> _x ) };
    		//Put back into attribute
    		_logic set3DENAttribute [ "allowedVehicles", _classes ];
    	};
    };

    Of course you could always provide two attributes( one for helos and other for landVehicles ). Maybe even a custom attribute control that error checks on user input.

     

    Think the above is correct, mainly going off of memory, but should provide you enough to search on.

     

  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow  Thanks for your reply.

The first solution is out of scope because I set the object presence to "is3den" or "true" depending on linked to my module. That works and it's far easier to let the mission maker link an helo in editor rather than searching for class (my bad). Of course, this object must not be present in game.

 

I already have two classes in my module:

 

class Attributes: AttributesBase
        {
            class defaultHelo: EDIT
              {
                property = "MGI_ModuleDropVeh_DefaultHelo";
                displayName = "Default helicopter";
                tooltip = "You can change for any existing class(es) of helicopter (case sensitive). Disabled if any linked helo to module.";
                typeName = "STRING";
                defaultValue = "'[""B_Heli_Transport_03_F"",""B_Heli_Transport_03_unarmed_F""]'";
            };
            class defaultVeh: EDIT
              {
                property = "MGI_ModuleDropVeh_DefaultVeh";
                displayName = "Dropped vehicle";
                tooltip = "You can change for any existing class(es) of vehicle (case sensitive). Disabled if any linked vehicle to module.";
                typeName = "STRING";
                defaultValue = "'[""B_LSV_01_armed_F"",""B_LSV_01_unarmed_F""]'";
            };
              class ModuleDescription: ModuleDescription{};
        };

 

That works fine with manual writing for classes but I failed to pass the arrays of linked vehicles (so in 3den) to these classes (as default value or result).

In fact, at this time, the unique way I found to make it work is to passe the value thru the profileNameSpace... not ideal.

 

Now I see your line:

expression = "_this setVariable ['%s',call compile _value];"; and the other related lines in the function.

I have to try that.

 

Thanks

 

 

 

Share this post


Link to post
Share on other sites

Finally, I got it:

in my hpp/cpp, the class is:

            class defaultHelo: EDIT
              {
                property = "MGI_ModuleDropVeh_DefaultHelo";
                displayName = "Default helicopter";
                tooltip = "You can change for any existing class(es) of helicopter (case sensitive). Disabled if any linked helo to module.";
                typeName = "STRING";
                //expression = "_this setVariable ['%s',call compile _value];"; // there is an already expression by default in EDIT class
                defaultValue = "'[""B_Heli_Transport_03_F"",""B_Heli_Transport_03_unarmed_F""]'"; // Default attribute value.
            };

in my module .sqf

Then, I had to refer to the entire property string, while using set3denAttribute in 3den scope:

                _logic set3DENAttribute ["MGI_ModuleDropVeh_defaultHelo",_heloString];  // within the case "connectionChanged3DEN":

 

And, after init, I just used a getVariable with the variable discriminant only in cpp:

           _heloString = _logic getVariable ["DefaultHelo",""];

 

Thanks again @Larrow , you showed me the right way.

Share this post


Link to post
Share on other sites

Everything works fine, now, when I open my module, I can see the updated attributes for helos and cars by default. that's workable.

 

Now, i'm trying to modify as well, the default attributes of the BI virtual supply drop which is linked to my module.

I can identify this linked BI module to mine. I can see by allVariables, the fields which I'm trying to modify (while in3den):

["bis_supp_vehicles","bis_fnc_moduleinit_status","bis_supp_vehicleinit","bis_supp_cooldown","bis_supp_crateinit","bis_supp_filter"]

 

Trying to modify the "bis_supp_vehicles" of the BI virtual drop, the weird thing is I can catch the updated manual written field of the BI module,  in console via getvariable, (but not get3denAtrribute??? erfff)

but, anyway, I couldn't set anything from my module function, neither with setVariable, nor set3denAttribute

As said above, set3denAttribute works for my module, but that doesn't work for updating the BI virtual supply...

EDIT: Solved.

in console, catch the module logic you need. Mine is:

((get3DENConnections (all3DENEntities select 3 select 1) apply {_x select 1}) select 0)

then look for

your_BImodule_logic getVariable "bis_supp_vehicles";

or :

your_BImodule_logic get3DENAttribute "SupportProvider_Virtual_Drop_BIS_SUPP_vehicles"

(here the module is a BI virtual drop provider)

now, you can modify, while in 3den, its default field (like vehicle types), by

your_BImodule_logic set3DENAttribute ["SupportProvider_Virtual_Drop_BIS_SUPP_vehicles","[""essai""]"]

 

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

×