ZNorQ 0 Posted August 22, 2007 #1; Can someone please explain the difference between the following script statements; - exec - execVM - spawn - preprocessFile - loadFile - call I've tried looking in wiki, but it only confuses me further, atleast when I tried to compare what it with other information that I picked off the forum. There is really no need to explain 'exec', as I'm very familiar with this script statement, but is it obsoloete / replaced by these other statements? #2; When do I use the 'compile' statement? ZNorQ Share this post Link to post Share on other sites
Synide 0 Posted August 22, 2007 #1; Can someone please explain the difference between the following script statements; - exec - execVM - spawn - preprocessFile - loadFile - call I've tried looking in wiki, but it only confuses me further, atleast when I tried to compare what it with other information that I picked off the forum. There is really no need to explain 'exec', as I'm very familiar with this script statement, but is it obsoloete / replaced by these other statements? #2; When do I use the 'compile' statement? ZNorQ Number One -exec = compile a script a script and run it now... the script is run within the current scripts thread. -execVM = compile a script and run it now... a new 'seperate' script thread is created independent of the current script thread from which it is being called. This is a great command as you can have a 'handle' to this executing thread which you can test to see if it's still running. use this (as oppssed to spawn) when the independent script is not going to be called very often. -spawn = essentially the same as above execpt it utilizes a already pre-compiled script. primarily for use if the script that's being called is being called alot of times. -preprocessFile = open a script file and pre-process it. pre-processing means it parses the script through the scripting engine, so it will do all the '#include' stuff in the script and pass back all the results basically a syntax checking mechanism. (see it's cousin command preprocessFileLineNumbers too) -loadFile = open a script and return it's contents... the contents of the loaded file don't necessarily need to be parseable ArmA script - but if it's not then you need to process it accordingly... i'm pretty sure there is no syntax checking done... that's what preprocessfile is used for... -call - there are 2 uses of this command...     1. you can use it the just 'call' a body of 'code' (not the type code)     or     2. if the script being called is a true 'function' and actually is meant to return a result then then you can use the 'call' command to do this...         eg. blah = [] call something;      - the result passed back from 'something' will be stored in 'blah'      - 'something' can be a variable name which is equal to a pre-compiled 'function' etc. personally i never use sqs syntax anymore... only sqf syntax and i find i hardly ever use 'exec' and 'loadfile' anymore. i use execVM, spawn, preprocessFileLineNumbers & call alot... Number Two you use 'compile' when you want to turn plain old text into code eg. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">vMonitor = compile preprocessFileLineNumbers "scripts\mp_server\vMonitor.sqf"; _handle1 = [_j,_l] spawn vMonitor; at this point the (global to this computer) variable vMonitor is equal to some 'compiled' code and is ready for action. so it can be referred in any other script on this machine, it can be 'called' time and time again - a 'lump' of code sitting in memory ready for your bidding. the 2nd line... if say 'vMonitor' expected a couple of parameters you could run it like that... which basically 'spawns' another scripting thread passes the 2 params and the handle to this thread is stored in '_handle1'... so you could test it with 'scriptDone'... or.... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> result = call compile {<some text that can be compiled>}; which basically compiles some 'text', runs it... and the 'result' is stored in the variable 'result'.... enough to go on with? Share this post Link to post Share on other sites
dr_eyeball 16 Posted August 22, 2007 Thorough reply, good summary. I wasn't certain that execVM runs in a separate thread. Does that mean it runs in parallel like spawn does? That might explain the random initialization differences I sometimes get. Anyone know what preprocessFileLineNumbers does? What "lines numbers" are they talking about, or is it simply the same as preprocessFile? Share this post Link to post Share on other sites
ZNorQ 0 Posted August 22, 2007 So, when executing a script, one have to take these considerations in account; - a) Memory usage - b) Speed - c) Number of times the script shall be executed When using spawn, one have to process the code using preprocessFile, which compiles and stores the code in memory. This is a speedy process, but it uses memory. If the script is only executed once (or a few times), one should consider using execVM, which doesn't store the code, just loads, compiles and executes. This is as slow process, but releases memory after use. This is the only difference between execVM and spawn, as both runs on a separate thread (it doesn't halt the "main script", as a function does (using call)), and both returns a handle which one can refer to to test if both scripts are still running or not... Did I understand it correctly? ZNorQ Share this post Link to post Share on other sites
ZNorQ 0 Posted August 22, 2007 @Dr Eyeball; Just a little off-topic message; The "ArmA_dialog_framework_v1.1" was yours, wasn't it? I wasn't aware of the huge improvements of ArmA dialogs! Amazing work, man! ZNorQ Share this post Link to post Share on other sites
.kju 3245 Posted August 22, 2007 excellent post Synide *dream mode ON* if this could be merge into the BIKI by anyone *dream mode OFF* maybe putting a link on the related sites in the BIKI to this thread would be a good compromise. Share this post Link to post Share on other sites
Synide 0 Posted August 22, 2007 @Dr Eyeball... yes, just like spawn... both commands create a asyncchronous scripting 'thread'. basically i use spawn & execVM for scripting stuff i want to run in the background... for instance i made a vehicle repawn script that only runs on the server, stays alive for duration of the number of respawns allowed for the given vehicle and is 1 script thread for each respawnable vehicle. it utilizes the in-built vehicle respawn but just like the 'createVehicle' respawn method too make it 'look' nice one has to have a 'script thread' monitoring the vechiles status - spawn in this case. preprocessFileLineNumbers? - basically you get the line numbers and pathname to the 'script' file inbedded in the resultant string... also, it puts the line numbers in the ArmA.rpt - a little easier to debug those astronomically long sqf files... @ZNorQ... Quote[/b] ]When using spawn, one have to process the code using preprocessFile, which compiles and stores the code in memory. This is a speedy process, but it uses memory. preprocessFile & preprocessFileLineNumbers doesn't 'compile' the text that represents script it just parses it - so if there are '#includes' etc. it'll pull all those together into 1 text stream and then parse it - Â sorry, it doesn't actually syntax check it at this point. the output of these 2 commands is text and should then be 'compiled' into code by using the 'compile' command. at this point it's ready for use by 'call', 'spawn'... etc. Quote[/b] ]If the script is only executed once (or a few times), one should consider using execVM, which doesn't store the code, just loads, compiles and executes. This is as slow process, but releases memory after use. yes, best suited to a smaller number of uses senario. whether it actually releases memory after it has finished executing only a dev. could tell you that - probably it does. to be 100% sure, one could always use the form of execVM that returns a 'script handle' and once complete set the variable to 'nil'. Quote[/b] ]This is the only difference between execVM and spawn, as both runs on a separate thread (it doesn't halt the "main script", as a function does (using call)), and both returns a handle which one can refer to to test if both scripts are still running or not... ... that's pretty much right... spawn takes code as it's input... code by definition here is 'compiled' script. whereas execVM takes a text string as it's input - the text string can either be the 'file' with the script text in it, or a variable that represents some 'script text'. just remember this... execVM compiles spawn does not. cheers... thanks Q... - but it's not like this topic hasn't been discussed before in these very forums... Share this post Link to post Share on other sites
zaphod 0 Posted August 22, 2007 i just collect my functions in a single sqf file and call it on top of init.sqf with: call compile preprocessfile "berzerk.sqf"; after that point all functions are call~ and spawnable ... that's it. the intention was, not to compile source or execute virtual machines on runtime, but who really knows what's "correct" ... regards, zap Share this post Link to post Share on other sites
Synide 0 Posted August 23, 2007 i just collect my functions in a single sqf file and call it on top of init.sqf with:call compile preprocessfile "berzerk.sqf"; after that point all functions are call~ and spawnable ... that's it. ...100% the intention was, not to compile source or execute virtual machines on runtime, but who really knows what's "correct" ...regards, zap ... what on earth gave you that idea?! Share this post Link to post Share on other sites
snkman 351 Posted August 15, 2010 Is there something we can use to execute a script and make the caller script wait till the called script was readed completly but without storing the content of the called script in memory? Currently i very often use: call compile preprocessFileLineNumbers Which does exactly what i need but the down side is that the code will be stored in memory and most of the scripts i execute this way are only needed for initialize which means they will be executed only onec the most time. I know the ways of how to "execVM" scripts and then wait for the script handler to be complete but this again is much slower then the way i use now... So what i'm looking for is something to execute scripts fast and make the other scripts wait till the script was readed completely but without storing the content of the script in memory. Guess there is nothing which will fit my needs? Share this post Link to post Share on other sites