philcommando 0 Posted February 18, 2005 I am a noobie when it comes to script, so i had to learn things the hard way. Generally, scripts do not lag as they will only be called upon to execute certain actions, then exit. Should the script be written wrongly, it either throws an error message at start or wont even execute at all. However, based on experiments, the majority of lags happening in scripts are from loop scripts - scripts that continually be called to exec action/actions within seconds. I realised that on a loop script, it would be better if u set conditions so that if it can find what it seeks, it moves on to another action without using cpu resources to search thru 400,000 objects on an island for the 1st action - every 0.02 seconds! example:- Quote[/b] ]#1 man1 setpos getpos car1 ~0.2 goto #1 this code will continually make man1's position relative to car1 every 0.2 seconds. Nothing wrong here but problem arise when there is no man1 or man1 is dead - for the script will continually search thru every object on the island every 0.2 seconds. If u put 10 such scripts - lag is scary. Possible solution:- conditions Quote[/b] ]#1 ?(!alive man1): goto exit man1 setpos getpos car1 ~0.2 goto #1 the first line is a condition meaning if man1 is not alive, exit out of the script, so if there is no man1 or man1 is dead, this script stops, freeing up cpu resources. Hope it may help someone. Disclaimer:- this is only an example script, kept small so that its concept may be understood. This post is not meant to boast my knowledge or display my intelligence for i have none. It was only meant to share a possible solution ( for i may be wrong but it was a solution that stop my lagging in scripts) with newbies like me who may have encountered this problem and not quite sure wat to do in the past. Not meant for more advance scripters. Share this post Link to post Share on other sites
Artak 0 Posted February 18, 2005 Quote[/b] ]#1man1 setpos getpos car1 ~0.2 goto #1 I would assume the above does nothing because goto bookmarks are handled as strings and you'd rather write: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#1 man1 setpos getpos car1 ~0.2 goto "1" Anyway, you're right. Conditional scripting is an important part of any scripting. Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 18, 2005 Generally said, the more information you want to gather/calculate at a certain time, the more lag you get. Or, the same amount of information in a much shorter time period. Share this post Link to post Share on other sites
Hit_Sqd_Ack 0 Posted February 18, 2005 What are you trying to do exactly? Are you looking for...? Q) You don't want the player to ever leave the car? A) Lock the Vehicle Assignment there by making the player not able to access functions like leaving the car. And then you could add a script if he died that would warp him into the car one time each time he perishes. Or..... Q) You want AI manning the car at all times? A) For this I would just use the aivehicle.sqs. Or you could make him part of a squad and put them else where and have it set to if the driver is empty then move 1 member of the squad into the drivers seat and execute the waypoint where the dead leader left off? Please clarify -Ack P.S. - You have nice addons Share this post Link to post Share on other sites
Chris Death 0 Posted February 19, 2005 @Hit_Sqd_Ack I assume that PC only used man1 and car1, ignoring the fact that it's setposs'ing a man onto a car, but to show what the rest of his text said. See it as man1 and car1 are only two random names, which were at this time when he wrote that cycling around in PC's head. Trying to setpos summit somewhere, what does not exist anymore (and this in a loop), will cause a lot of stress for the cpu  P.S: good find PC ~S~ CD Share this post Link to post Share on other sites
philcommando 0 Posted February 19, 2005 thanks for the corrections and help by you folks, but err..the script is just a simple example of using conditions to prevent lag. Loop scripts are one of the best way to further enhance missions but oooh, we sure do need to apply it gently or gameplay is gone. Share this post Link to post Share on other sites
sanctuary 19 Posted February 20, 2005 An interesting idea would be to make a collection of hints&tips to optimize scripting, then maybe once enough is collected to post it in a single post in the Mission Editing FAQ. As it is an already sticky thread, such post should be really helpfull there to help people with sometime simple, but overlooked hits&tips that can make a decisive difference between a good mission and a "laggy" mission that had good potential. Share this post Link to post Share on other sites