Jump to content
ramon_dexter

custom function fails on first call

Recommended Posts

So, I got some custom functions defined via cfgFunctions.hpp. One of these functions is function to change color of screen, based on surfer's screen effects from Contention Zone.

The code is this (fnc\dx\setColor.sqf):

params["_barva"]; 
 
    dx_Color = [];  
    dx_clear = [1.0, 1.0, 0.0, [0,0,0,0], [0,0,0,1], [0,0,0,0]]; 
    dx_dexter = [1.0, 1.6, 0.0, [1.1, 0.9, 0.8, 0.05], [0.9, 0.6, 0.2, 0.5],  [0.199, 0.587, 0.114, 0.0]]; 
    dx_surfer = [1.0, 1.6, 0.0, [1.1,0.9,0.8,0.05], [1.2,1.0,0.2,0.4], [0.199,0.587,0.114,0.0]]; 
    dx_dark = [1, 1.35, -0.32, [0.8,0.8,0.8,0],[0.8,0.8,0.8,0.5],[0.8,0.8,0.8,0]];

    dx_Color = _barva;  
 
    _screenColor = ppEffectCreate ['ColorCorrections', 2000];  
    _screenColor ppEffectEnable true;  
    _screenColor ppEffectAdjust dx_Color;  
    _screenColor ppEffectCommit 0;

Definition in cfgFunctions.hpp:

class DX {
		class base {
			class randomSentence {
				file = "fnc\dx\randomSentence.sqf";
			};
			class treesProximityCheck {
				file = "fnc\dx\treesProximityCheck.sqf";
			};
			class anomalyMarker {
				file = "fnc\dx\anomalyMarker.sqf";
			};
			class univIconMarker {
				file = "fnc\dx\univIconMarker.sqf";
			};
			class setColor { //this one
				file = "fnc\dx\setColor.sqf";
			};
			class setGrain {
				file = "fnc\dx\setGrain.sqf";
			};
		};
	};

Include in description.ext:

#include "cfg\functions.hpp"

 

And the code itself is called by custom menu, and also in initPlayerLocal.sqf:

[] spawn {
    [dx_clear] call dx_fnc_setColor;
    sleep 5;
    [dx_clear] call dx_fnc_setColor;
    sleep 5;
    [dx_dexter] call dx_fnc_setColor;
};

The problem is that the first call throws error that 'dx_color' and '_barva' and the 'dx_clear' in function call is not defined. I don't understand the bug, because second time (and next and next and next) the script works as intended. What's wrong? Do I need to precompile, or pre-call it before the mission is loaded? If so, how do I do that?

 

EDIT:

Solved by defining the vars in initPlayerLocal.sqf

Share this post


Link to post
Share on other sites
On 9/6/2019 at 7:22 PM, ramon_dexter said:

The problem is that the first call throws error that 'dx_color' and '_barva' and the 'dx_clear' in function call is not defined.

I assume your variable isn't defined then.

 

On 9/6/2019 at 7:22 PM, ramon_dexter said:

I don't understand the bug, because second time (and next and next and next) the script works as intended.

Sounds like your variable is defined before you do the second call.

 

On 9/6/2019 at 7:22 PM, ramon_dexter said:

What's wrong?

The game tells you that the variable is undefined. So "what's wrong" is that the variable is undefined when you call that function.

Share this post


Link to post
Share on other sites
On 9/6/2019 at 6:22 PM, ramon_dexter said:

//initPlayerLocal.sqf

[] spawn {
    [dx_clear] call dx_fnc_setColor;

 

At this point dx_clear is undefined.

 

When the function executes all the dx_ values get defined. but _brava will be nil, so so will dx_color

On 9/6/2019 at 6:22 PM, ramon_dexter said:

params["_barva"]; 
 
    dx_Color = [];  
    dx_clear = [1.0, 1.0, 0.0, [0,0,0,0], [0,0,0,1], [0,0,0,0]]; 
    dx_dexter = [1.0, 1.6, 0.0, [1.1, 0.9, 0.8, 0.05], [0.9, 0.6, 0.2, 0.5],  [0.199, 0.587, 0.114, 0.0]]; 
    dx_surfer = [1.0, 1.6, 0.0, [1.1,0.9,0.8,0.05], [1.2,1.0,0.2,0.4], [0.199,0.587,0.114,0.0]]; 
    dx_dark = [1, 1.35, -0.32, [0.8,0.8,0.8,0],[0.8,0.8,0.8,0.5],[0.8,0.8,0.8,0]];

    dx_Color = _barva;  

 

 

The next call from the code in initPlayerLocal.sqf

On 9/6/2019 at 6:22 PM, ramon_dexter said:

    sleep 5;
    [dx_clear] call dx_fnc_setColor;

 

Now dx_clear has been defined, by the previous call to the function.

 

Maybe put those definitions( dx_ variables ) either at the top of initPlayerLocal or maybe a preInit function.

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

×