Jump to content
Jonas Coper Steuerfahndung

Need help with a little code (Trigger)

Recommended Posts

Hello,
Just starting new with scripting and don't understand why this code doesn't work:

 

File is executed but trigger is not activated:

 

this AddAction ["Repair vehicle", "fixVehicle.sqf",{myCustomActionActivation = true;
    (_this select 0) removeaction (_this select 2)}];

 

Trigger is activated but file is not executed:

 

{"this addAction [
    ""Repair vehicle",{myCustomActionActivation = true;
    (_this select 0) removeaction (_this select 2)}, "fixVehicle.sqf"];

I can either just activate the trigger or just execute the file.

 

 

Only one of the two ever works

Thanks for the help

 

Share this post


Link to post
Share on other sites

The Biki entry for addAction has a useful example (#5):

//Default parameters with comments:

this addAction
[
	"title",	// title
	{
		params ["_target", "_caller", "_actionId", "_arguments"]; // script
	},
	nil,		// arguments
	1.5,		// priority
	true,		// showWindow
	true,		// hideOnUse
	"",		// shortcut
	"true",		// condition
	50,		// radius
	false,		// unconscious
	"",		// selection
	""		// memoryPoint
];

The parameters of an addAction come in the form of an array. Each element/index of the array serves a purpose and requires a specific type of data.

 

Your first snippet places your code block in the arguments index, wrapped in curly brackets, which is easier to see when we expand it vertically, like in the example above:

this AddAction 
[
	"Repair vehicle", 
	"fixVehicle.sqf",
	{
		myCustomActionActivation = true;
		(_this select 0) removeaction (_this select 2);
	}
];

So the script is called, but the code block fails.

 

The script index of addAction can take either a script filename as a string

Quote

"fixVehicle.sqf"

 

or a code block

(myCustomActionActivation = true;
(_this select 0) removeaction (_this select 2);

but NOT both.

 

 

Your second snippet is fairly broken.

 

So how to do this? Simple, either move the code block to the script, or call the script from the codeblock. The latter is the simplest:

//script from codeblock:

this AddAction 
[
	"Repair vehicle", 
	{
		execVM fixVehicle.sqf;
		myCustomActionActivation = true;
		(_this select 0) removeaction (_this select 2);
	}
];

And we can even use addAction's params to make things a little cleaner:

//script from codeblock:

this AddAction 
[
	"Repair vehicle", 
	{
		params ["_target", "_caller", "_actionId", "_arguments"];
		execVM fixVehicle.sqf;
		myCustomActionActivation = true;
		_target removeaction _actionId;
	}
];

 

Meanwhile, the former requires we pass the action ID to the script, and I haven't had my coffee yet.

 

 

  • 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

×