paramsArray: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(work in progress)
 
mNo edit summary
Line 1: Line 1:
If ''class Params'' is defined in [[description.ext]], a simple "Parameters" GUI becomes available in Multiplayer which allows the host (or admin on dedicated server) to define custom mission parameters before mission start. These params will become available to all mission scripts via paramsArray variable, which contains [[Array]] of values selected via "Parameters" GUI.
If ''class Params'' is defined in [[description.ext]], a simple "Parameters" GUI becomes available in Multiplayer which allows the host (or admin on dedicated server) to define custom mission parameters before mission start. These params will become available to all mission scripts via paramsArray variable, which contains [[Array]] of values selected via "Parameters" GUI.


<gallery>
File:params.png|"Parameters" GUI
File:params_options.png|Available Options
File:params_edit.png|Editing Options
</gallery>


<syntaxhighlight lang="javascript">class Params
<syntaxhighlight lang="javascript">class Params

Revision as of 14:20, 22 March 2014

If class Params is defined in description.ext, a simple "Parameters" GUI becomes available in Multiplayer which allows the host (or admin on dedicated server) to define custom mission parameters before mission start. These params will become available to all mission scripts via paramsArray variable, which contains Array of values selected via "Parameters" GUI.

class Params
{
	class paramsArray_select_0
	{
		title = "Item 1"; //item name
		texts[] = {"One","Two","Three"}; //item text options (visible)
		values[] = {1,2,3}; //item value options (can only be integers)
		default = 1; //actual value (in values[]) to be set as default
	};
	class paramsArray_select_1
	{
		title = "Item 2";
		texts[] = {"Ten","Twenty","Thirty"};
		values[] = {10,20,30};
		default = 20;
	};
	class paramsArray_select_2
	{
		title = "Item 3";
		texts[] = {"One Hundred","Two Hundred","Three Hundred"};
		values[] = {100,200,300};
		default = 300;
	};
	//default value of paramsArray is [1,20,300]
};

Practical example of setting mission time of the day on mission start.

description.ext part:

class Params
{
	class Hours
	{
		title = "Mission Time / Hours";
		texts[] = { \
			"00","01","02","03","04","05", \
			"06","07","08","09","10","11", \
			"12","13","14","15","16","17", \
			"18","19","20","21","22","23" \
		};
		values[] = { \
			0,1,2,3,4,5,6,7,8,9, \
			10,11,12,13,14,15,16, \
			17,18,19,20,21,22,23 \
		};
		default = 12;
	};
	class Minutes
	{
		title = "Mission Time / Minutes";
		texts[] = {"00","10","20","30","40","50"};
		values[] = {0,10,20,30,40,50};
		default = 0;
	};
};

init.sqf part:

if (isServer) then { _date = date; _date set [3, paramsArray select 0]; _date set [4, paramsArray select 1]; setDate _date; };