paramsArray: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(work in progress)
 
(Fix redirection)
Tag: Redirect target changed
 
(6 intermediate revisions by 4 users not shown)
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.
#REDIRECT [[Mission Parameters]]
 
 
<syntaxhighlight lang="javascript">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]
};</syntaxhighlight>
 
Practical example of setting mission time of the day on mission start.
 
''description.ext part'':
 
<syntaxhighlight lang="javascript">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;
};
};</syntaxhighlight>
 
''init.sqf part'':
 
<code>[[if]] ([[isServer]]) [[then]] {
_date = [[date]];
_date [[set]] [3, [[paramsArray]] [[select]] 0];
_date [[set]] [4, [[paramsArray]] [[select]] 1];
[[setDate]] _date;
};</code>

Latest revision as of 17:48, 31 October 2021

Redirect to: