Jump to content
draoth

Need help passing arguments with BIS_fnc_Spawn

Recommended Posts

Hey, 

I'm trying to globally execute a script. but i get an error.

 

Script i use to execute:

Spoiler

[_veh,_AI,_AI2,_AI3,_wp,_pass, "hitchhiking.sqf", "BIS_fnc_execVM", true, true] call BIS_fnc_Spawn;

 

Script i'm executing:

Spoiler

_veh = _this select 0;
_AI = _this select 1;
_AI2 = _this select 2;
_AI3 = _this select 3;
_wp = _this select 4;
_pass = _this select 5;

_chance = selectrandom [1,2,3];
waituntil {pris1 distance _veh <10 || pris2 distance _veh <10};
if (_chance == 3 && vehicle pris1 == pris1) then {
_AI disableAI "all";
if (_Pass > 1) then {_AI disableAI "all"; _AI2 disableAI "all";
};
if (_Pass > 2) then {_AI disableAI "all"; _AI2 disableAI "all"; _AI3 disableAI "all"; 
};
_veh engineOn false;
if (Pris1 == player) then {
hint "Get in you pieces of shit, this will be a hell of a ride";
};
if (Pris2 == player) then {
hint "Get in you pieces of shit, this will be a hell of a ride";
};

sleep 2;
pris1 moveInAny _veh;
pris2 moveInAny _veh;
sleep 2;
_AI enableAI "all";
_AI disableAI "AUTOCOMBAT";
if (_Pass > 1) then {_AI enableAI "all"; _AI2 enableAI "all"; _AI2 disableAI "AUTOCOMBAT";
};
if (_Pass > 2) then {_AI enableAI "all"; _AI2 enableAI "all"; _AI3 enableAI "all";  _AI3 disableAI "AUTOCOMBAT";
};
sleep 240;
_AI disableAI "all";
if (_Pass > 1) then {_AI disableAI "all"; _AI2 disableAI "all";
};
if (_Pass > 2) then {_AI disableAI "all"; _AI2 disableAI "all"; _AI3 disableAI "all"; 
};
_veh engineOn false;
if (Pris1 == player) then {
hint "I'm not helping you cunts any further. I hope you'll die.";
};
if (Pris2 == player) then {
hint "Get in you pieces of shit, this will be a hell of a ride";
};

sleep 2;
//pris1 moveInAny _veh;
//pris2 moveInAny _veh;
sleep 2;
doGetOut pris1;
doGetOut pris2;

_veh engineOn true;
_AI enableAI "all";
_AI disableAI "AUTOCOMBAT";
if (_Pass > 1) then {_AI enableAI "all"; _AI2 enableAI "all"; _AI2 disableAI "AUTOCOMBAT";
};
if (_Pass > 2) then {_AI enableAI "all"; _AI2 enableAI "all"; _AI3 enableAI "all";  _AI3 disableAI "AUTOCOMBAT";
};
};
sleep 2;

 

Error:

Spoiler

Error : type OBJECT, Expected code, on index 1 in blablabla

 

I hope anyone can help me

Share this post


Link to post
Share on other sites

Well this is wrong on multiple levels. 

 

1. BIS_fnc_Spawn only takes 1 or 2 arguments See: https://community.bistudio.com/wiki/BIS_fnc_spawn (This is the cause of your error)

2. Using "Spawn" to call "ExecVM" is basically redundant as both commands function mostly the same.  Spawn is better for calling compiled functions or code. ExecVM for calling script files.

3. This doesn't do anything globally. This is only run on the machine where the script is executed. You'll want to take a look at https://community.bistudio.com/wiki/remoteExec to exec commands across multiple machines.

 

To do any form on remote execution it's better to compile the script in to function first. Pretty much all the information is available at:

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

I strongly recommend you read this.

 

If you just want to run the script locally you can do the following

[_veh,_AI,_AI2,_AI3,_wp,_pass] execVM "hitchhiking.sqf" 

For this example the  "hitchhiking.sqf" file will have to be in the root of your mission directory (e.g next to the mission.sqm file)

I also believe it is better practice to use the script commands instead of the functions wherever possible (others may differ on this). So BIS_fnc_Spawn is just spawn and BIS_fnc_ExecVM is just execVM.

 

**Not tested**

I believe the following will call your script globally, You may need to whitelist the execVM command within CfgRemoteExec. But I can't doing this recommend this and is a better option to compile your script into a function as mentioned earlier.

 

"hitchhiking.sqf" remoteExec ["execVM", 0];

 

 

Information on all scripting commands can be found

https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

and for functions

https://community.bistudio.com/wiki/Category:Arma_3:_Functions

 

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
9 hours ago, R. Razor [WP] said:

Well this is wrong on multiple levels. 

 

1. BIS_fnc_Spawn only takes 1 or 2 arguments See: https://community.bistudio.com/wiki/BIS_fnc_spawn (This is the cause of your error)

2. Using "Spawn" to call "ExecVM" is basically redundant as both commands function mostly the same.  Spawn is better for calling compiled functions or code. ExecVM for calling script files.

3. This doesn't do anything globally. This is only run on the machine where the script is executed. You'll want to take a look at https://community.bistudio.com/wiki/remoteExec to exec commands across multiple machines.

 

To do any form on remote execution it's better to compile the script in to function first. Pretty much all the information is available at:

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

I strongly recommend you read this.

 

If you just want to run the script locally you can do the following


[_veh,_AI,_AI2,_AI3,_wp,_pass] execVM "hitchhiking.sqf" 

For this example the  "hitchhiking.sqf" file will have to be in the root of your mission directory (e.g next to the mission.sqm file)

I also believe it is better practice to use the script commands instead of the functions wherever possible (others may differ on this). So BIS_fnc_Spawn is just spawn and BIS_fnc_ExecVM is just execVM.

 

**Not tested**

I believe the following will call your script globally, You may need to whitelist the execVM command within CfgRemoteExec. But I can't doing this recommend this and is a better option to compile your script into a function as mentioned earlier.

 


"hitchhiking.sqf" remoteExec ["execVM", 0];

 

 

Information on all scripting commands can be found

https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

and for functions

https://community.bistudio.com/wiki/Category:Arma_3:_Functions

 

 

 

Oops, i've copied the wrong one. I was really desperate so i tried multiple variations of the code to make it work. The correct one is BIS_fnc_mp instead of spawn. 

Quote

"hitchhiking.sqf" remoteExec ["execVM", 0];

Do you believe this will work on a script that has been filtered by isserver? That would be even better since  BIS_fnc_mp kills your framerate if you use it alot. 

 

Share this post


Link to post
Share on other sites
13 minutes ago, draoth said:

Do you believe this will work on a script that has been filtered by isserver? That would be even better since  BIS_fnc_mp kills your framerate if you use it alot. 

 

BIS_fnc_mp is literally the same thing as remoteExec.

And yes that will work in a script that's run serverside if you "filter" by isServer.

  • Sad 1

Share this post


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

BIS_fnc_mp is literally the same thing as remoteExec.

And yes that will work in a script that's run serverside if you "filter" by isServer.

Thanks man.  I'm just a guy with almost no scripting experience and i'm not a native english speaker so i don't know all the 

technical terms. No need to act so clever ;)

Share this post


Link to post
Share on other sites

Ok, everything works with BIS_fnc_mp. But since it's unstable and laggy, how can i use remoteExec and still pass my arguments?

I tried: 

[_veh,_AI,_AI2,_AI3,_wp,_pass] "hitchhiking.sqf" remoteExec ["execVM", 0]; 

but it doesn't seem to work. (no errors but script doesn't work)

 

 

Share this post


Link to post
Share on other sites

The syntax for passing the parameters in shown on the remoteExec page I linked previously and is shown as such:

// <params1> someScriptCommand <params2>;

[<params1>, <params2>] remoteExec ["someScriptCommand", targets, JIP];

 

 

I would expect the correct format for what you want would be.

[ [_veh,_AI,_AI2,_AI3,_wp,_pass],"hitchhiking.sqf" ] remoteExec ["execVM", 0]; 

// To explain what is going on a little bit.

[_veh,_AI,_AI2,_AI3,_wp,_pass] is your <param1>
"hitchhiking.sqf" is your <param2>
  
You should notice this pattern from the my original response where
  <param1> execVM <param2>
Becomes:
  [_veh,_AI,_AI2,_AI3,_wp,_pass] execVM "hitchhiking.sqf";
    
When passing multiple parameters into the a command they have to be passed as an array e.g [ <param1>, <param2> ] 
    notice the [ and ] being added.    

Hopefully this will work, it's possible I have made a mistake. If you are unsure I really do recommend ready in the documentation i linked, while I understand it may not be the most understandable for people new to scripting.

It really is a great resource, just take you time and read it carefully.

 

If the performance is an issue when using BIS_fnc_MP then that'll likely still be the case  as Dedman mentioned they are basically the same thing.

BIS_fnc_MP exists purely for backwards compatibility for older scripts. Any performance issue is then likely caused by your "hitchhiking.sqf" script.

 

Just as a bonus a lot of information and additional resources are listed here.

While may not help with this specific issue you are having, it can never hurt having more information available.

 

  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, R. Razor [WP] said:

The syntax for passing the parameters in shown on the remoteExec page I linked previously and is shown as such:

// <params1> someScriptCommand <params2>;

[<params1>, <params2>] remoteExec ["someScriptCommand", targets, JIP];

 

 

I would expect the correct format for what you want would be.


[ [_veh,_AI,_AI2,_AI3,_wp,_pass],"hitchhiking.sqf" ] remoteExec ["execVM", 0]; 

// To explain what is going on a little bit.

[_veh,_AI,_AI2,_AI3,_wp,_pass] is your <param1>
"hitchhiking.sqf" is your <param2>
  
You should notice this pattern from the my original response where
  <param1> execVM <param2>
Becomes:
  [_veh,_AI,_AI2,_AI3,_wp,_pass] execVM "hitchhiking.sqf";
    
When passing multiple parameters into the a command they have to be passed as an array e.g [ <param1>, <param2> ] 
    notice the [ and ] being added.    

Hopefully this will work, it's possible I have made a mistake. If you are unsure I really do recommend ready in the documentation i linked, while I understand it may not be the most understandable for people new to scripting.

It really is a great resource, just take you time and read it carefully.

 

If the performance is an issue when using BIS_fnc_MP then that'll likely still be the case  as Dedman mentioned they are basically the same thing.

BIS_fnc_MP exists purely for backwards compatibility for older scripts. Any performance issue is then likely caused by your "hitchhiking.sqf" script.

 

Just as a bonus a lot of information and additional resources are listed here.

While may not help with this specific issue you are having, it can never hurt having more information available.

 

Thank you man, i will checkout the links!

Have a good day

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

×