Jump to content
Waldemar 337

Starting the compiled SQF script from the SQS script

Recommended Posts

Hello.

 

How can I start the compiled SQF script from the SQS script ?

I have tried using the 'call' command, but it does not work.

 

init.sqf:

Mca_fnc_onVehicleFueled = compile preprocessFileLineNumbers "Script\Mission\Mca_fnc_onVehicleFueled.sqf";

 

some.sqf:

_taskTargetObject addEventHandler 
[
	"fuel", { [] spawn { quest_giver globalChat "1"; (_this select 0) call Mca_fnc_onVehicleFueled; } }
];

Mca_fnc_onVehicleFueled.sqf:

quest_giver globalChat "Mca_fnc_onVehicleFueled.sqf";

 

When the event handler fires, the first instruction works (i see the "1" in chat), but the compiled script is not started.

 

Thank you.

Share this post


Link to post
Share on other sites
28 minutes ago, Waldemar 337 said:

_taskTargetObject addEventHandler 
[
	"fuel", { [] spawn { quest_giver globalChat "1"; (_this select 0) call Mca_fnc_onVehicleFueled; } }
];

 

This script won't work. You are creating a new independent scope with the spawn command and passing no arguments ( [] ) to the new function. Instead try this:
 

_taskTargetObject addEventHandler 
[
	"fuel", { quest_giver globalChat "1"; (_this select 0) call Mca_fnc_onVehicleFueled; }
];

Or if you really have to spawn it:

_taskTargetObject addEventHandler 
[
	"fuel", { _this spawn { quest_giver globalChat "1"; (_this select 0) call Mca_fnc_onVehicleFueled; } }
];

 

Btw there is no "sqs" in any of your scripts. What did you mean by that?

Share this post


Link to post
Share on other sites
12 minutes ago, 7erra said:

Btw there is no "sqs" in any of your scripts. What did you mean by that?

As far as I know, the code of the event handler (E.H.) must be provided as an SQS script.

The 'sleep' command does not work in the E.H., so I think it really uses the SQS syntax.

It is not directly mentioned on BIS's page, but they use an SQS file in the example 1:

 

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

Example 1:

_EHkilledIdx = player addEventHandler ["killed", {_this exec "playerKilled.sqs"}]

If I am wrong, please correct me.

 

P. S.

 

I need the 'spawn' command to use 'sleep' inside an SQF script.

The first method raises an error.

The second version works great!

Thanks!

 

Share this post


Link to post
Share on other sites

True, the first example is sqs. But it is perfectly okay (and normal) to use sqf.

this addEventhandler ["Fuel", {_this execVM "script.sqf";}];

The BIKI documentation seems a bit old. This one seems to be from April 2006 when the page was first created.

 

Spawning the eventhandler and then calling a function is a bit redundant. You can just spawn the function from the eventhandler:

_taskTargetObject addEventHandler 
[
	"fuel", { quest_giver globalChat "1"; (_this select 0) spawn Mca_fnc_onVehicleFueled; }
];

This makes the _this variable accessible in the EH scope directly.

Share this post


Link to post
Share on other sites
On 1/26/2020 at 7:39 PM, 7erra said:

True, the first example is sqs.

no its not.

Its a SQF script, exec'ing a sqs script. The script in the eventhandler itself is SQS.

And it doesn't say anywhere on that wiki page that it needs to be SQS code.

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

×