Jump to content
thy_

[SOLVED] Calling custom function stored in a file through a class expression

Recommended Posts

Happy New Year, gentlemen. 

 

I'm studying how to use the CfgCommunicationMenu in-game and I got stuck!

 

Here below is what I got based on BIKI example.

// File: /mission_folder/description.ext

class CfgCommunicationMenu
{
	class request_ext_by_air
	{
		text = "Request Air Extraction";
		...
		expression = "player setVariable ['BIS_SUPP_request', ['Artillery', _pos]];";	// Code executed upon activation
		...
		enable = "1";  // Simple expression condition for enabling the item
		removeAfterExpressionCall = 1;
	};
};

 

// Calling it by scripting or Eden trigger, e.g:
[player,"request_ext_by_air"] call BIS_fnc_addCommMenuItem;


Here is the function that I want to call in-game, using the support menu:

// file: /mission_folder/support_request_heli.sqf

params ["_vehToUse", "_posToGo"];
private ["_wp"];

_wp = group (driver _vehToUse) addWaypoint [_posToGo, 0];
_wp setCurrentWaypoint _wp;

// return:
true;

 

Back in the description.ext, this line is the answer but my brain doesn't help as I need... How can I call the custom function above through this line below?

expression = "player setVariable ['BIS_SUPP_request', ['Artillery', _pos]];";	// Code executed upon activation

Share this post


Link to post
Share on other sites
22 minutes ago, thy_ said:

expression = "player setVariable ['BIS_SUPP_request', ['Artillery', _pos]];";

 

expression = "call support_request_heli";

Share this post


Link to post
Share on other sites
10 minutes ago, gc8 said:

 

expression = "call support_request_heli";

 

But and those parameters "_vehToUse" for example? 😅

 

I have tried this way but I failed:

expression = "player setVariable ['support_request_heli', ['heliTest']];";

Considering my custom function parameters currently are like this:

params [["_vehToUse", objNull], ["_posToGo", getPosATL player]];

 

Share this post


Link to post
Share on other sites
5 minutes ago, thy_ said:

But and those parameters "_vehToUse" for example? 😅

 

it should work because the _this variable is left untouched

but you could also do

 

expression = "_this call support_request_heli";

 

and refer to this: https://community.bistudio.com/wiki/Arma_3:_Communication_Menu#Expression_Arguments

(though it shows global variables.. should be local instead)

 

so you can also do

 

expression = "[vehicle player, _pos] call support_request_heli";

 

  • Like 1

Share this post


Link to post
Share on other sites

Oh, now I see my lack of information.

@gc8 the '_vehToUse' parameter is an AI vehicle that all I know is its variable name in-game (heliTest).

 

That said, I have NO experience with setVariable and getVariable, and always I need to use global vars I use this simplest way below. That's why the BIKI example is so confusing for my understanding.

Spoiler

MyExample = objNull;
publicVariable "MyExample";

 

 

I would like to use that class expression naming what the vehicle should be used for that action. Can you give me some examples of how to call that specific vehicle (heliTest) or a smarter way to define which AI vehicle should be used (I know, it sounds too open-scope)? 

 

Share this post


Link to post
Share on other sites

cant you just use:

 

expression = "[heliTest, _pos] call support_request_heli";

?

 

Share this post


Link to post
Share on other sites

Nope. I'm missing something...

i6e0CmG.png

 

nc6eEQp.png

 

vSRJmt2.png

 

T7c8u8H.png

ps: heliTest spawns in the air and stays there, just hovering in the same position after the request. 

 

Result:

So I use the Support option to call "Request Extraction..." and nothing happens. No feedback messages (systemChat). 

 

@gc8

Share this post


Link to post
Share on other sites

well make sure the script/function is called. also remember to reload your description.ext

 

im off, hope you get it sorted out!

 

Share this post


Link to post
Share on other sites

Now it's working.

 

I replaced 'call' with 'execVM' and its format:

expression = "_this execVM 'support_request_heli.sqf'";

And the custom function needs to use those BIS arguments/params as you mentioned.

// File: support_request_heli.sqf

private ["_caller", "_pos", "_target", "_is3D", "_id"];

_caller = _this # 0;  // this is the unit set in here on Eden's trigger: [player, "request_ext_by_air"] call BIS_fnc_addCommMenuItem;
_pos    = _this # 1;  // the _caller position;
_target = _this # 2;  // the _caller aim position during the request;
_is3D   = _this # 3;  // if the _caller used the FPS point-of-view (3d) to request the support or if they used the map (2d);
_id     = _this # 4;  // the _caller id;

systemChat format ["_caller: %1", _caller];
systemChat format ["_pos: %1", _pos];
systemChat format ["_target: %1", _target];
systemChat format ["_is3D: %1", _is3D];
systemChat format ["_id: %1", _id];

<custom function code using these local vars above...>
  
// Return:
true

 

Solved.

  • Like 1

Share this post


Link to post
Share on other sites

good to hear you got it working.

i guess the problem was that you did not define support_request_heli variable. this is my bad i forgot to tell you

 

you can define it like this:

 

support_request_heli = compileScript ["support_request_heli.sqf"];

 

then the call should work

  • Thanks 1

Share this post


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

you can define it like this:

 


support_request_heli = compileScript ["support_request_heli.sqf"];

 

 

I've read about compileScript but I have no clue where to define the script as you mentioned. I've tried some posts like this one in the forum and nothing, so I tried to apply through init.sqf, initServer.sqf, and inside the description.ext (non-sense hehe) but I couldn't figure that out.

 

I could just leave the expression line using execVM but calling a compiled script sounds better for server performance.

 

 

Share this post


Link to post
Share on other sites
17 minutes ago, thy_ said:

I could just leave the expression line using execVM but calling a compiled script sounds better for server performance.

 

yep its little bit better than execVM

 

weird that init.sqf didnt work (Maybe wrong path?)

 

you can always put the support_request_heli in debug console and see if it shows the code, if so its defined, if nothing then not defined

 

  • Like 1

Share this post


Link to post
Share on other sites
16 minutes ago, gc8 said:

weird that init.sqf didnt work (Maybe wrong path?)

 

The function is working okay but declaring it via init.sqf is raising a "Suspending not allowed in this context" error. This is absolutely new for me. I'm reading about...

Share this post


Link to post
Share on other sites
11 minutes ago, thy_ said:

 

The function is working okay but declaring it via init.sqf is raising a "Suspending not allowed in this context" error. This is absolutely new for me. I'm reading about...

 

ah then you must spawn it instead of call

 

https://community.bistudio.com/wiki/spawn

 

  • Thanks 1

Share this post


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

ah then you must spawn it instead of call

Of course. I know how works spawn and call but for some reason, I didn't realize I could explore the spawn benefits in the class too. Thanks.

 

Now it's working flawlessly:

// description.ext:
expression = "_this spawn support_request_heli";

// init.sqf
support_request_heli = compileScript ["support_request_heli.sqf"];

Done!

  • Like 1

Share this post


Link to post
Share on other sites
11 hours ago, thy_ said:

 

I've read about compileScript but I have no clue where to define the script as you mentioned. I've tried some posts like this one in the forum and nothing, so I tried to apply through init.sqf, initServer.sqf, and inside the description.ext (non-sense hehe) but I couldn't figure that out.

 

I could just leave the expression line using execVM but calling a compiled script sounds better for server performance.

 

 

Could I just take this moment to strongly recommend using the Functions Library to define your scripts into proper Functions: Arma 3 Functions Library

 

Automatic compilation before anything runs. Your code will always be available as a missionNamespace variable TAG_fnc_functionName.

And yes the code only compiles once.

 

It's a different workflow than just creating sqf files, but very easy to work with once you get it set up and can really help keeping things neat and organised.

  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, mrcurry said:

Could I just take this moment to strongly recommend using the Functions Library to define your scripts into proper Functions: Arma 3 Functions Library

 

Hey, @mrcurry you mean like this one? Thanks for the advice and that was very much appreciated. The code in this topic is just a prototype for a new feature of CSWR script. So my idea here was just make it run without create the entire structure and this "simplest" way is exactly where I have some gaps in A3 scripting knowledge.

Share this post


Link to post
Share on other sites
10 hours ago, thy_ said:

 

Hey, @mrcurry you mean like this one? Thanks for the advice and that was very much appreciated. The code in this topic is just a prototype for a new feature of CSWR script. So my idea here was just make it run without create the entire structure and this "simplest" way is exactly where I have some gaps in A3 scripting knowledge.

Nice! Then you really don't need to worry about performance of compile Vs execVM at such an early stage, just get it working. 🙂

 

That said you can do rapid prototyping with CfgFunctions too. If you are still using VSCode you can setup a user snippet to quickly generate the CfgFunctions entry for use in a prototype mission, when you're done testing the resulting function file is ready to be dropped straight into a larger project with no changes.

 

Tomato tomato and whatever floats the boat

  • Thanks 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

×