Jump to content
  • 0

Difference in code?


Tricks

Question

3 answers to this question

Recommended Posts

  • 0

Every time you use the execVM, spawn, or call commands, whatever value is immediately before the command is passed onto the execVM'ed/spawned/called code as the magic variable _this.

 

Quick demonstration:

//Scenario 1:
[0,1,2] execVM "script.sqf"; //If _this is used inside script.sqf, it would be equal to [0,1,2]. Useful if you want to pass multiple values to a script.

//Inside script.sqf:
diag_log str(_this); //This would produce output of "[0,1,2]" in your RPT log.


//Scenario 2:

1 execVM "script.sqf"; //If _this is used inside script.sqf, it would be equal to 1. Do this if you only want to pass a single value to a script.

//Inside script.sqf:
diag_log str(_this); //This would produce output of "1" in your RPT log.


If you use execVM with nothing before it, the value passed would be a nil (undefined) value for _this. If you missed a semicolon on the previous line, you'll be passing the result of previous line into the execVM statement, so be careful. Personally I would always put something before every execVM/spawn/call command. If I have no value to pass on, I'd just put a 0 or [] before it. This can be especially important when using the call command, so that you can avoid passing the _this value of the calling script to the _this value of the called script.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...