Home   Help Search Login Register  

Author Topic: mk4_processParamsArray (parameters made easy)  (Read 3847 times)

0 Members and 1 Guest are viewing this topic.

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
mk4_processParamsArray (parameters made easy)
« on: 22 Sep 2009, 18:40:56 »
Usually when dealing with parameters you need to always check at which index the parameter is before you can get the value. Because this is such a cumbersome method, I decided to make a script that would not require indices anymore, and instead get the code that belongs to the parameter from inside the parameter class (where it should've been imho).

It is very easy to make your parameters compatible with my processParamsArray script so you never have to bother about indices ever again.


The only thing you have to do, besides from copying my script to your folder, is to put a code value in your parameter classes, like so:

Code: [Select]
class ViewDistance // 0
{
title = "View Distance:";
values[] = { 1200, 1500, 2000, 2500, 3000 };
texts[] = { "1.2 km", "1.5 km", "2 km", "2.5 km", "3km" };
default = 2000;
code = "setViewDistance %1";
};

As you can see in this example the code value here is setViewDistance %1, but what does the %1 stand for? If you are not familiar with the format command, it stands for a placeholder that will be replaced with an actual value later on, in this case a value from the parameters value array (values[]).
So assuming that the player doesnt change the default setting for this parameter, the value for this parameter will become 2000 because that's what the default is set too. The script then gets this value and replaces the %1 with the param value, so you'll end up with something like this: setViewDistance 2000.

After the script replaced %1 with the appropriate value, it then compiles and executes the code.


That's it really, look for more examples in the description.ext



NB. Valid values for parameters are integers, floats and booleans (true=1 and false=0). In Arma 2 1.04 floats malfunction when used in default values.


mk4_processParamsArray 0.1
« Last Edit: 26 Sep 2009, 01:06:13 by mikey »

Offline i0n0s

  • Moderator
  • *****
Re: mk4_processParamsArray (poc)
« Reply #1 on: 23 Sep 2009, 03:41:39 »
Looks good, if you add a read me, you can add it as a resource ;)

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re: mk4_processParamsArray (poc)
« Reply #2 on: 24 Sep 2009, 11:49:30 »
Very useful, mikey!

Here's some extra code to initialise the param1, param2 and paramsArray variables with values in case one runs a MP mission as a single-player mission or previews it in the normal ("SP") editor. It will set up these variables with their default values:
Code: [Select]
if (isNil "param1" && isNumber(missionConfigFile/"defValueParam1")) then
{
param1 = getNumber (missionConfigFile/"defValueParam1");
};
if (isNil "param2" && isNumber(missionConfigFile/"defValueParam2")) then
{
param2 = getNumber (missionConfigFile/"defValueParam2");
};

if (isNil "paramsArray") then
{
paramsArray=[];

if (isClass (missionConfigFile/"Params")) then
{
_c=count (missionConfigFile/"Params");
for [ {_i=0}, {_i<_c}, {_i=_i+1} ] do
{
_paramName = (configName ((missionConfigFile >> "Params") select _i));
paramsArray=paramsArray+[ getNumber (missionConfigFile >> "Params" >> _paramName >> "default") ];
};
};
_c=count paramsArray;
if (isNil "param1" && _c>0)then{param1=paramsArray select 0};
if (isNil "param2" && _c>1)then{param2=paramsArray select 1};
};

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
Re: mk4_processParamsArray (parameters made easy)
« Reply #3 on: 25 Sep 2009, 12:07:47 »
Looks nice killswitch, will definitely be adding that to my template since I also always edit in the SP editor.

Anyhow, I've updated the example mission with some more "complicated" examples and a readme. Now, how do I add it as a resource (I think I haven't had "the talk" yet It's added! ;))
« Last Edit: 26 Sep 2009, 01:05:37 by mikey »

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: mk4_processParamsArray (parameters made easy)
« Reply #4 on: 15 Dec 2009, 13:40:02 »
Thanks mikey. Found that very useful.  :good:

Auto initialize for editor by Killswitch is neat as well.
I did it somewhat similar, yet non generic for my AAS MOD.