Jump to content
Sign in to follow this  
Tankbuster

call, execVM and spawn, which and when?

Recommended Posts

Guys,

Can someone help with some guidance here? I see all these ways of firing up a script, which of these is best in a given circumstance?

I imagine that one type is suited best to a script that only ever runs once in a mission and another is best for a script that runs over and over again?

Thanks,

Tanky

Share this post


Link to post
Share on other sites

spawn, wiki explains this well.

call, is used to run a codeblock and wait until a result is returned, (code is completedm unlike spawn who just goes ahead).

execVM, is used to call .sqf scripts only, ( note difference between sqs(old) and sqf(new) )

  • Like 1

Share this post


Link to post
Share on other sites

spawn and execVM are asynch, which means they will start a new tread, the calling thread will continue paralell. execVM is reading from the HDD, compiles, and run, spawn is pre-compiled. To rephrase this: spawn can spawn codeblocks (or precompiled sqf file), execVM executes sqf file.

call is always run first, and if it finishes, calling script continues. Call can return a value, spawn and execVM can only return its handle. Called scripts need to be precompiled.

Some examples for usage:

-Rarely called scripts are better to execVM-d

-scripts used many times are better to be precompiled, and called

-functions (scripts with return values) must be called

-parallel scripts (like checking multiple flying parachutes) are spawned.

note! The variables of a called script can interfere with the calling script, so use private statement inside called scripts!

Edited by zapat

Share this post


Link to post
Share on other sites

Got it now. :)

My script is quite heavy on the server but will only be run half a dozen times during a game. The script itself uses preprocessFileLineNumbers for a sort routine which. I think execVM is the one for me.

I've carefully privated all the scripts variables and named them so they won't conflict with others. I'm now looking into what variable I should pass to it.

Thanks everyone, very helpful.

Share this post


Link to post
Share on other sites
I can't call functions with comments within. Why?

You have not preProcessed it OR you have pasted the code directly into one of the fields in the editor. The editor does not allow comments.

Share this post


Link to post
Share on other sites

Is there a potential problem when calling identical code concurrently?

Allow me to explain - in my IED kit, the IED disruptors (reconfigged satchels) are placed near an IED that is hidden by a clutter object. The IEDs have handledamage on them and that knows when it's been hit by the disruptor blast. Problem is sometimes, the IED are quite close to each other and a single disruptor can destroy more IED up to a range of ~10m.

The initial solution was to make the disruptor less powerful, but then, some of the clutter objects shielding the IED from it's blast. Ideally, the disruptor would be directional, but as it's really a satchel under the bonnet, it can't be.

So... I added a firednear to all the IEDs which knows when the satchel is put (note, putting a satchel generates a fired near. Setting it off doesn't) and then getting the distance between it and the IED when it goes off and ideally, ignoring all but the closest one. But the disruptor ceases to exist when it goes off, crucially before the handledamage fires in the IED. Grrr.

So, solution is have the firednear in the IEDs call a function that makes an invis heli pad at the position of the disruptor and then, when the disruptor goes off, use the distance between the pad and the IED to make sure it's the furthest IEDs that ignore and handledamage they might get.

But, my question is and I'm sorry it took so long to get here is, supposing there's more than 1 IED near where the disruptor is placed. firednear will trigger more than once and call the function that handles the helipad creation and stuff. Is there any problem with having the same code being fired more that one, concurrently? Could the variables and logics within the function pollute each other if they are running at the same time?

I ask because

(1) I'm getting unexpected results in trying to make this work, chief among this is it works in editor preview, but not on a DS. Normally this would suggest a locality issue, but I've created the helipad using a number of diffferent ways. In any case, all of this stuff should be server side only.

(2) I'm not even convinced my logic is sound. :)

(3) It's making my head hurt.

Share this post


Link to post
Share on other sites

 [] call compile preProcessFileLineNumbers "script.sqf"

runs script and waits for it to return

execVM is basically the same thing as writing

[] spawn {_this call compile preProcessFileLineNumbers "script.sqf"};

as far as I've understood.

Is there any reason why you can't run at least some of the stuff on the clients? Like using a fired eventhandler on the player? And when he fires it, delete the closest IED and create a fake explosion or something. I've noticed sometimes that if you are far away from an object, the positions of the object (at least for player objects) might differ by several meters. I don't know if this is true for servers however, as it shouldn't be. However a general note is that the more stuff you can handle on clients, the better. It's kind of hard to help you without seeing any code.

Share this post


Link to post
Share on other sites

fired EH is weird for satchels. It goes off when the satchel is placed, not when it actually explodes.

As far as I can see, running much stuff on the clients just complicates it further. If the fired EH is on the player and you want to delete an IED because of it, you have to cross the locality boundary because the IEDs are on the server. Unless I'm missing your point. :)

Share this post


Link to post
Share on other sites

That's how I'd expect the satchels to work as well.

I have no idea what your code looks like, but deleteVehicle is a global command.

Share this post


Link to post
Share on other sites

Good point - never thought of that. There's other stuff like addscore which must happen on the server, mind.

At the moment, I'm going about it a slightly different way. When firednear sees a disruptor being placed, it finds it then puts an emptyhelipad at the same pos.

Then in the handledamage for the IED, there's a condition that only runs the 'ied_killed' function if the damage was done by a disruptor AND theres a helipad within 3 metres. It's working in SP, just need to see if it's MP and DS safe. :)

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
Sign in to follow this  

×