Jump to content
alpha993

Passing Variable Array to Description.ext

Recommended Posts

Hey all,

 

I've been trying to pass a variable containing an array into the mission parameters in my description.ext using preprocessor commands, but I've had no luck so far. I'm not very familiar with the preprocessor commands as it is, so I'd greatly appreciate if anyone could point me in the right direction.

 

What I'm trying to do step-by-step:

  1. Create two 'string' arrays in a preInit function, one with just numbers, and the other with just strings. 
    • e.g. ALP_arrayNum = "0, 1, 2, 3, 4, 5" & ALP_arrayText = " 'zone0', 'zone1', 'zone2', 'zone3', 'zone4', 'zone5' "
  2. Store those 'string' arrays into two variables.
    • see example above.
  3. Compile the variables so that they get the braces required by config arrays.
    • ALP_arrayNum becomes {0, 1, 2, 3, 4, 5}
    • ALP_arrayText becomes {'zone0', 'zone1', 'zone2', 'zone3', 'zone4', 'zone5'}
  4. Declare those variables in the description.ext using preProcessor commands.
    • Using __EXEC or __EVAL?
  5. Define the values[] and texts[] attributes in the params class using those two variables.
  6. This way I can achieve a dynamic parameter that doesn't need to be rewritten by hand whenever the mission is modified or ported to other maps.

 

// === PARAMETERS

class Params
{
	class ALP_selectedArea
	{
		title = "Main Zone";
		values[] = {}; 	//<--------DEFINE THIS WITH VARIABLE CONTAINING ARRAY OF NUMBERS
		texts[] = {};	//<--------DEFINE THIS WITH VARIABLE CONTAINING ARRAY OF STRINGS
		default = 0;
	};
};

 

My attempts:

 

#1 -- This one throws a "_ found, { expected" error

// === PARAMETERS

class Params
{
	class ALP_selectedArea
	{
		title = "Main Zone";
		values[] = __EVAL(ALP_arrayNum);
		texts[] = __EVAL(ALP_arrayText);
		default = 0;
	};
};

 

#2 -- This one doesn't throw an error, but returns 'any' in the params menu, presumably because it's actually duplicating the braces like values[] = {{0, 1, 2, 3, 4, 5}}

// === PARAMETERS

class Params
{
	class ALP_selectedArea
	{
		title = "Main Zone";
		values[] = {__EVAL(ALP_arrayNum)};
		texts[] = {__EVAL(ALP_arrayText)};
		default = 0;
	};
};

 

#3 -- This one behaves like #1, where it throws a "_ found, { expected" error

// === PARAMETERS

#define ZONEVAL                     values[] = __EVAL(ALP_arrayNum);
#define ZONETXT                     texts[] = __EVAL(ALP_arrayText);

class Params
{
	class ALP_selectedArea
	{
		title = "Main Zone";
		ZONEVAL
		ZONETXT
		default = 0;
	};
};

 

Again, any help would be greatly appreciated!

Share this post


Link to post
Share on other sites

I have, but no matter what I do the variables aren't passed successfully. I've tried dozens of approaches and the best I can get is the variables returning "any."

 

I'm starting to think it's not possible to use preInit-defined variables as they seem to not get their values until after the lobby screen.

Share this post


Link to post
Share on other sites

OK, sorry I couldn't help.

I'd suggest dropping by Arma discord and ask on #scripting channel.

  • Like 1

Share this post


Link to post
Share on other sites

You could try
 

parsingNamespace setVariable ["ALP_arrayNum", [0, 1, 2, 3, 4, 5] ];

 

In preinit

 

Not sure, my memory is kinda bad with these things

  • Like 1

Share this post


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

You could try


parsingNamespace setVariable ["ALP_arrayNum", [0, 1, 2, 3, 4, 5] ];

 

 

I gave it a shot, but the best I get is a <null> in the parameters.

 

class Params
{
	class ALP_testParam
	{
		title = __EVAL(parsingNamespace getVariable ["ALP_test","test"]);
		values[] = {__EVAL(parsingNamespace getVariable "ALP_arrayNum")};
		texts[] = {__EVAL(parsingNamespace getVariable "ALP_arrayText")};
		default = 0;
	};
};

 

I'm pretty sure PreInit functions just don't run until after the mission lobby, as the "ALP_test" variable in the title was defined as "paramTitle" in the PreInit, but it's instead showing up as the default "test," meaning it's undefined.

Share this post


Link to post
Share on other sites
12 hours ago, alpha993 said:

pretty sure PreInit functions just don't run until after the mission lobby, 

 

There's an easy way to check, put a diag_log in your preinit function and run it and review the log file while in the lobby

  • Like 1

Share this post


Link to post
Share on other sites
15 hours ago, alpha993 said:

I gave it a shot, but the best I get is a <null> in the parameters.

 

 

Edit:

 

Actually the right syntax is this:

 

description.ext:

 

testStr = __EVAL(testStrVar123);

 

 

Where testStrVar123 is string in parsingNamespace (But it doesn't work because preinit is called after the parse)

 

 

And that's just for string, I don't know about array

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/13/2022 at 6:29 AM, gc8 said:

 

And that's just for string, I don't know about array

 

I forgot that __EVAL only returns numbers or strings, so I'm pretty much out of luck with this since I need to return a curly bracketed array.

 

The alternative would be to use a different variable for each element of the array (like in BI's paramCountdown.inc file), but that would just be too much of a headache for this approach to be worth it, especially considering my arrays would vary in size.

For example, here's how BI does it in paramCountdown.inc, where each _countdown variable is defined previously in an __EXEC command:
 

values[] = {
		-1,
		__EVAL(_countdown0),
		__EVAL(_countdown1),
		__EVAL(_countdown2),
		__EVAL(_countdown3),
		__EVAL(_countdown4),
		__EVAL(_countdown5),
		__EVAL(_countdown6),
		__EVAL(_countdown7),
		__EVAL(_countdown8),
		__EVAL(_countdown9),
		__EVAL(_countdown10)
	};

 

Share this post


Link to post
Share on other sites

Yeah that's kinda the thing with configs, the data is assumed to be fairly static, simple and read-only stuff. 🙂

 

I can't off top of my head think of a use case for what you are trying to achieve. If you wish to provide more info on your situation we may be able to figure out an alternative approach.

Share this post


Link to post
Share on other sites

I have a mission that creates an area of operations by selecting one trigger out of several placed in the editor. I then have a parameter which tells the game to either pick a trigger randomly, or select a specific one (only one area of operations is active during the mission, similar to King of the Hill). The reason I wanted a dynamic parameter is so I can add or remove triggers, and have the parameter automatically update itself accordingly. Otherwise, I would have to manually type in each trigger, which gets tedious when you have over twenty. Such an automated approach would also make it extremely simple to port the mission to other maps, as all you would need to do is place your triggers and not worry about editing the parameters.

In any case, I made an alternative approach by creating a function that detects all triggers and then writes the parameter config for me.  It's not the fully automated system I was hoping for as I have to run the function every time I port the mission or make significant changes, but it's better than typing everything manually.

  • Like 1

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

×