Jump to content
Neviothr

Setting a slider's position using the onLoad event

Recommended Posts

I have this slider:

class RscSlider;

class nevDebugMenu {
	duration = 99999;
	idd = 80000;
	onLoad = "call NEV_fnc_onLoad";
	class controls {
		// A slider to change the overcast value
		class overcastSlider: RscSlider {
		    idc = 80003;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (285 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change overcast";
		};
	};
};

I want to set it to a certain position whenever the dialog is loaded. This is how NEV_fnc_onLoad looks:

NEV_fnc_onLoad = {
	_dialog = findDisplay 80000;
	_slider = _dialog displayCtrl 80003;
	sliderSetRange [80003, 0, 10];
	sliderSetPosition [80003, 5];
}

Unfortunately, it doesn't seem to work. The slider appears fine, is moveable, but when the dialog is loaded, it's in the leftmost position (0), while in theory, it needs to be in the middle of the slider (position 5). Does anyone know how to fix/achieve this?

Thanks.

Share this post


Link to post
Share on other sites

Hi

do you have error reporting on?

the NEV_fnc_onLoad  is missing ";" from the end "}"

 

Share this post


Link to post
Share on other sites

Try something like this:

 

class RscSlider;

class nevDebugMenu {
	duration = 99999;
	idd = 80000;
	onLoad = "_nul = [""onLoad"",this] call NEV_fnc_nevDebugMenu;"; // changed expression and function call
	class controls {
		// A slider to change the overcast value (look at RscXSlider - more pretty version of RscSlider)
		class overcastSlider: RscSlider {
		    idc = 80003;
		    x = "SafeZoneX + (960 / 1920) * SafeZoneW";
		    y = "SafeZoneY + (285 / 1080) * SafeZoneH";
		    w = "(200 / 1920) * SafeZoneW";
		    h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change overcast";
                    onSliderPosChanged = "_nul = [""sliderMoved"",this] call NEV_fnc_nevDebugMenu;"; // added onSliderPosChanged event handler
		};
	};
};

NEV_fnc_nevDebugMenu:

 

Just as a heads up, the overcast values range from 0 to 1, as such, I have ammended your sliders range values. It is better to describe functions in the CfgFunctions and let the game handle this for you. From preference I try to bundle the display script/handler functions in to one program and switch between different modes (best to only use this for up to 10 different modes).

// check if calling machine has interface
if !(hasInterface) exitWith {};

_this params [
	["_mode","",[""]],
	["_params",[],[[]]]
];

switch (_mode) do {
	//-------------------------------------------------------
	// onload - executed when interface load handler is fired
	case "onLoad" : { 
		_params params [
			["_display",displayNull,[displayNull]]
		];

		// check if display was passed
		if (isNull _display) exitWith {};

		// set slider position
		_sliderCtrl = _display displayCtrl 80003;
		_sliderCtrl sliderSetRange [0,1];
		_sliderCtrl sliderSetPos 0.5;
	};
	//-------------------------------------------------------
	// sliderMoved - executed when slider position is changed
	case "sliderMoved" : {
		_params params [
			["_sliderCtrl",controlNull,[controlNull]],
			["_sliderPos",0,[0]]
		];

		// check control was passed
		if (isNull _sliderCtrl) exitWith {};

		// get display to update other controls
		_display = ctrlParent _sliderCtrl;

		// set the overcast from slider value
		0 setOvercast _sliderPos;
		forceWeatherChange; // submits the change (best to have this on a submit button as it needs to sync to all clients)
	};
	//-------------------------------------------------------
	// default case - displays error message for invalid mode
	default {
		_nul = ["NEV_fnc_debugMenu: '_mode' was invalid!"] call BIS_fnc_error;
	};
};
          

(I haven't tested this code)

 

Hope this helps point you in the right direction :)

 

Bull

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, gc8 said:

Hi

do you have error reporting on?

the NEV_fnc_onLoad  is missing ";" from the end "}"

 

If after } there are no more statements or another } it is not a probem

Share this post


Link to post
Share on other sites

Thank you for your help, but unfortunately, @bull_a I wasn't able to get your code to work properly for me. And having this been the 6th or 7th time I've tried creating weather sliders - I've decided to settle for a much dumber, and inefficient solution.

debug_menu.hpp:

class RscSlider;
class RscButton;

class nevDebugMenu {
	duration = 99999;
	idd = 80000;
	onLoad = "call NEV_fnc_onLoad";
	class controls {
		// A slider to change the overcast value
		class overcastSlider: RscSlider {
		    idc = 80003;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (285 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change overcast";
		};

		// A slider to change the lightning value
		class lightningSlider: RscSlider {
		    idc = 80004;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (330 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change lightning";
		};

		// A slider to change the fog's value
		class fogValueSlider: RscSlider {
		    idc = 80005;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (375 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change fog value";
		};

		// A slider to change the fog's decay value
		class fogDecaySlider: RscSlider {
		    idc = 80006;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (420 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change fog decay";
		};

		// A slider to change the fog's base value
		class fogBaseSlider: RscSlider {
		    idc = 80007;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (465 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change fog base";
		};

		// A slider to change the rain value
		class rainSlider: RscSlider {
		    idc = 80008;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (510/ 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change rain";
		};

		// A slider to change the wave value
		class waveSlider: RscSlider {
		    idc = 80009;
		   	x = "SafeZoneX + (960 / 1920) * SafeZoneW";
			y = "SafeZoneY + (555 / 1080) * SafeZoneH";
			w = "(200 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
		    type = CT_SLIDER;
		    style = SL_HORZ;
		    tooltip = "Change waves";
		};

		// A button to commit weather changes
		class commitWeather: RscButton {
			text = "Change Weather";
			x = "SafeZoneX + (810 / 1920) * SafeZoneW";
			y = "SafeZoneY + (420 / 1080) * SafeZoneH";
			w = "(100 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
			type = CT_BUTTON;
			style = ST_CENTER;
			action = "call NEV_fnc_commitWeather";
			tooltip = "Commit weather changes";
		};
	};
};

NEV_fnc_onLoad:

NEV_fnc_onLoad = {
	_dialog = _this select 0;

	// Overcast slider
	_overcastSlider = _dialog displayCtrl 80003;
	_overcastSlider sliderSetRange [0, 1];
	_overcastSlider sliderSetPosition overcast;

	// Lightnings slider
	_lightningSlider = _dialog displayCtrl 80004;
	_lightningSlider sliderSetRange [0, 1];
	_lightningSlider sliderSetPosition lightnings;

	// Fog value slider
	_fogValueSlider = _dialog displayCtrl 80005;
	_fogValueSlider sliderSetRange [0, 1];
	_fogValueSlider sliderSetPosition (fogParams select 0);

	// Fog decay slider
	_fogDecaySlider = _dialog displayCtrl 80006;
	_fogDecaySlider sliderSetRange [0, 1];
	_fogDecaySlider sliderSetPosition (fogParams select 1);

	// Fog base slider
	_fogBaseSlider = _dialog displayCtrl 80007;
	_fogBaseSlider sliderSetRange [0, 1];
	_fogBaseSlider sliderSetPosition (fogParams select 2);

	// Rain slider
	_rainSlider = _dialog displayCtrl 80008;
	_rainSlider sliderSetRange [0, 1];
	_rainSlider sliderSetPosition rain;

	// Waves slider
	_wavesSlider = _dialog displayCtrl 80009;
	_wavesSlider sliderSetRange [0, 1];
	_wavesSlider sliderSetPosition waves;
}

NEV_fnc_commitWeather:

NEV_fnc_commitWeather = {
	// Overcast
	_overcast = sliderPosition 80003;
	86400 setOvercast _overcast;

	// Lightnings
	_lightning = sliderPosition 80004;
	0 setLightnings _lightning;

	// Fog
	_fogValue = sliderPosition 80005;
	_fogDecay = sliderPosition 80006;
	_fogBase = sliderPosition 80007;
	0 setFog [_fogValue, _fogDecay, _fogBase];

	// Rain
	_rain = sliderPosition 80008;
	0 setRain _rain;

	// Waves
	_waves = sliderPosition 80009;
	0 setWaves _waves;

	forceWeatherChange;
}

If anyone knows how to make the above better, feel free to share.

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

×