Home   Help Search Login Register  

Author Topic: Preprocess file \ ExecVm and sqf  (Read 2158 times)

0 Members and 1 Guest are viewing this topic.

Offline Eymerich

  • Members
  • *
Preprocess file \ ExecVm and sqf
« on: 28 May 2007, 10:32:15 »
Hi,

I wuold like to understand the different beetwen a single sqf function ( [] call _MyFunction) and the different command _nul = [_this] execVm "Myfunction.sqf".

The second function doesn't return a value (instead the first one).
However, are there any other differences beetwen them?
And when is it supposed to use the first one instead the second one?
I've read that the "ExecVm" is much faster than the simple [] exec "script.sqs". But: are there any side-effects?

And: Preprocess a function is a great way to improve your script.
However: how many functions can I pre-process?
And, again, this last function, has any side effect?
(For exemple: can I preprocess 20 or 30 Functions?)

Sorry for many questions...

Regrads

Eymerich

 :)








Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Preprocess file \ ExecVm and sqf
« Reply #1 on: 28 May 2007, 11:26:08 »
execVM compiles and executes the corresponding sqf file and returns a handle to the executing script. Basically, it is a replacement in some cases of "exec".
But as said before, execVM looks for the file, loads it, compiles it and executes it. Conclusion: it is quite well suited for sqf scripts that have a "long" execution time with loops inside and Sleeps between loop iterations.

For a quick and fast calculation, on the other side, you have two options:
- If it is going to be used by several scripts, sqf and sqs, then create a function and call it (remember you cannot use sleeps there).
- If it is going to be used in the middle of the loop of an sqf script only, then just put your calculation code there, no need to create any function cause you are not going to get any performance improvement (remember that execVM compiles the code).

You may use also "spawn" command, which will execute the provided code in the same way execVM does, it will return also a script handler.

With returned script handlers (execVM and spawn), you may control the execution of the corresponding scripts from outside them checking their "script-finished" state with scriptDone command.

Code: [Select]
_handler = []execVM"myscript.sqf"
@scriptDone _handler
hint "Script done"

Offline Eymerich

  • Members
  • *
Re: Preprocess file \ ExecVm and sqf
« Reply #2 on: 28 May 2007, 19:38:27 »
Thank you..

That's bring me to another question:

Is there any difference beetwen ExecVm and the simple exec?

Why should I use the the first and not the second?
I'm asking this because in a some mission I've downloaded  user mostly prefer the "execVm" instead than "exec.sqs".

And... for preprocess?  ???

Regards :)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Preprocess file \ ExecVm and sqf
« Reply #3 on: 28 May 2007, 20:20:38 »
exec only works with sqs scripts
execVM only works with sqf scripts
for sqf functions you may use
functionhandler = compile (preprocessFileLineNumbers "functionname.sqf");
to call it
result = [whatever, whatever, ...] call functionhandler
« Last Edit: 29 May 2007, 10:08:06 by Mandoble »

Offline Eymerich

  • Members
  • *
Re: Preprocess file \ ExecVm and sqf
« Reply #4 on: 29 May 2007, 10:03:27 »
for sqf functions you may use
functionhandler = compile (preprocessFileLineNumbers "functionname.sqf");
to call it
result = [whatever, whatever, ...] call functionhandler

 ??? --> :confused: -->  :blink:

Don't get it... sorry.


Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Preprocess file \ ExecVm and sqf
« Reply #5 on: 29 May 2007, 10:13:28 »
Functions needs to be loaded and compiled before executed.

Code: [Select]
//suma.sqf
_result  = (_this select 0)+(_this select 1)+(_this select 2)+(_this select 4);
_result


Code: [Select]
;init.sqs
sumahandler = compile (preprocessFileLineNumbers "functionname.sqf")

Now, where you need to use it:
Code: [Select]
_result = [1,5,7,2] call sumahandler

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Preprocess file \ ExecVm and sqf
« Reply #6 on: 29 May 2007, 10:24:25 »
Not trying to confuse but Mandoble why do you use the preprocess stuff like that?

Thinking in laymen logic that slows down the process because the file is preprocessed and compiled 'simultaneously' (I guess preprocessFilexxx has priority though) and then immediately after that function is the executed, and this all happens 'on the fly'..

Again in laymen logic it would seem that preprocessing the function way before it needs to be used (like doing it in the init.sqs/sqf) would speed up the process, of course such a minor speed issue is not relevant to like 99% of scripts..

But what the hell do I know.. :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Preprocess file \ ExecVm and sqf
« Reply #7 on: 29 May 2007, 10:30:54 »
It doesnt slows down anything, you do it only one single time in your init.sqs, then you have the function handler you will use in any further call to the function, which is global, so you may use it anywhere.

Did I understood correctly your question?  ???

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Preprocess file \ ExecVm and sqf
« Reply #8 on: 29 May 2007, 10:38:00 »
Right, misread your post a bit, and I had on mind another example that 'style' was used in and somehow I made it in mind to look like the preprocess and the call were consecutively in the same script  :-[  :no:

When do I learn that I should not come here babling on when I'm in a cataclysmic hurry  :D :whistle:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Preprocess file \ ExecVm and sqf
« Reply #9 on: 29 May 2007, 10:54:59 »
In fact, you may do that:

Code: [Select]
[arg1, arg2, arg3] call compile (preprocessFileLineNumbers "functionname.sqf")

But, of course, if you plane to call it many times (for example in a loop), the best way would be to preprocess and compile it only once.

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: Preprocess file \ ExecVm and sqf
« Reply #10 on: 30 May 2007, 09:17:49 »
What is the difference between preprocessFileLineNumbers and preprocessFile?
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)