Taurus 20 Posted July 5, 2007 I have some questions about scripts. In ArmA we have execVM - threaded script spawn - threaded script(same as execVM?) call - function then there are some ways to compile them compile preProcessFile "myScript.sqf" what does preProcessFile mean other than it supports // /**/ comments and stuff stated in the wiki? I have a feeling some scripts are still present in the memory even tho they have done their execution if you use the same script twice or more, like <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while{someThing} do{ _scriptHandler = [_dynamicVariable1, _someOtherThing] spawn compile preProcessFile "myScript.sqf"; }; Because it seems that the fourth or fifth time the "myScript.sqf" fails doing what it is supposed to, variables defined in it which are changed wont change and etc? I have a script that moves a truck along some waypoints(markers) with "commandMove" and sometimes it just doesn't move, even tho it did before. (I think I will have to post a new thread about this matter when I've been testing around abit) And lastly As there are no sequential ways of exec scripts we need to use waitUntil{scriptDone(_myScript)}; do prevent the script engine to hurry past that one last script execution and move on to the other? I hope I was clear in what my questions were, if not, let me know and I will try to clarify things. Thanks for any advice regarding scripting .sqf-style! Share this post Link to post Share on other sites
UNN 0 Posted July 5, 2007 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while{someThing} do{  _scriptHandler = [_dynamicVariable1, _someOtherThing] spawn compile preProcessFile "myScript.sqf"; }; Quote[/b] ]Because it seems that the fourth or fifth time the "myScript.sqf" fails doing what it is supposed to, variables defined in it which are changed wont change and etc? Scripts staying in memory won't cause them to fail. The way your calling the above code, is not the best use of the spawn command. It should look more like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">MyScript=compile preProcessFile "myScript.sqf"; while {someThing} do     {     _scriptHandler = [_dynamicVariable1, _someOtherThing] spawn MyScript;     }; MyScript=nil; When you want to unload the script, set MyScript equal to nil. Quote[/b] ]As there are no sequential ways of exec scripts Thats what the Call command is for. Although you have to be carefull if you executing large scripts or ones that demand lots of CPU time. Share this post Link to post Share on other sites
Taurus 20 Posted July 5, 2007 Thanks UNN helpful as always! I would probably PM you, but it might help others too. Are there some "best practice" in usage of scripts, like skeleton-snippets or tutorials available somewhere? I tried searching ofpec but I failed. Thanks again, [edit] My kitchen table got upset that I didn't put a smily to thank you. (better not upset it more...*hyssch*) Share this post Link to post Share on other sites
UNN 0 Posted July 6, 2007 Quote[/b] ]Are there some "best practice" in usage of scripts, like skeleton-snippets or tutorials available somewhere?I tried searching ofpec but I failed. Not really seen much in the way of scripting tutorials, along those lines. But I rekon it's a hard topic to tackle, as there are so many ways of doing the same thing and they all have thier own merrits. Quote[/b] ]Thanks again No worries Share this post Link to post Share on other sites
Taurus 20 Posted July 15, 2007 UNN or anyone else, if you could help me out to see if understand this correctly. I began using the myScript = compile preProcessFile "myScript.sqf"; And realized that nil = [] spawn myScript; Would make an "instance" of that script, which could be reused As this actually seems to improve performance and will not(?) make the game engine puke after a while, which using nil = [] spawn compile preProcessFile "myScript.sqf"; each time seems to do, making the game engine puke that is. if I put myScript = compile preProcessFile "myScript.sqf"; in the init-file and nil = [] spawn myScript; server side And nil = [] spawn myScript; Client side. Will the server and client use the same instance or will they get one of their own? Because if it did use the same instance that would be as a "singelTon" in java yes/no? Its probably the latter but just to be sure. Share this post Link to post Share on other sites
Doolittle 0 Posted July 15, 2007 The client and server are two completely different computers... two different memory spaces. They only communicate with each other through publicVariable and game objects (when a server does createVehicle, the client will "see" it). When you do myscript = compile preProcessFile "myscript.sqf"... I like to think of it as though myscript is now a really long string. That's all. If you do player sidechat str myscript, you can actually see all your code with the carriage returns stripped out. This is also how you can see the difference between loadFile and preProcessFile... the only diff that I see is preProcess actually strips out the comments but loadFile doesn't. So when you run a spawn, it only runs on that one machine. And spawn is more like saying "take this string of code and run through it". Doolittle Share this post Link to post Share on other sites
Taurus 20 Posted July 18, 2007 k, thanks It was semi-obvious, but I needed to ask, I also realized why I came up with this idea... I had a script running server side which placed markers on objects created. I had that script "global" and as the markers showed on the remote client I thought "omg??". Now I've just found out(by checking the small icons on the wiki LOL) that markers are global [edit] And not to mention the text after Multiplayer: Share this post Link to post Share on other sites