Jump to content
Sign in to follow this  
jaenak

Good editing practices

Recommended Posts

hehe Rasta.

Loop timings

Dont know in what order these run at, eg fastest to slowest

Some clarification would be nice

Triggers, loops to check if condition is true at what rate???

@, loops to check if condition is true at what rate

~, loops at what rate

Triggers run every 1/2 second or so, if their condition is This

if their condition is anything else, my uinderstanding is, they run every frame.

@ runs every frame

~ tells the program when to call it, and it calls. ~ is by far the most efficient.

In an addon, Tag every global variable.

Another reason for requiring passing arrays to functions is that it's consistent practive. Now I have functions out there that take something other than an array, and I gotta say debugging-wise they're the biggest pain in the asses, not simply because I don't get an error some of the time, but also becuase every time I call that function I have to remember that it doesn't take an array.

In other words, always passing arrays to functions is a good SOP.

Share this post


Link to post
Share on other sites
Quote[/b] ]

Second point: No you are incorrect in my opinion, any scripter can lose a lot of time using non array passing if the system is complex enough, for example the Net services from CoC.  Or if you make utility functions, you _never_ want to leave someone with a function that won't even drop a syntax error, how will you debug it when someone jsut tells you in their large MP session your script didn't run, sometimes, but only with 12 people on.  I think you underestimate the problems that can occur.  Sticking to good scripting practices is usually more important than a slight cometic appeal, or slight CPU usage reduction. (usually)

Well scripts like the net services are really rare in the OFP community. There are only around 5 different "complex" scripts packages (including most of your scripts). Most scripts are around 10 - 20 lines at most and of a real simple nature.

Those simple scripts are most times simple to debug, even under different conditions.

As I wrote you do the complex stuff, so you have most experience in complex debugging and that way you are right that it makes sense to stick to your pratices.

Dinger: I do it like: one variable --> no array, more then one --> array (ofcourse). I dont have to remember that since I used that so often that I simply write (..) when only one variable is needed (which is infact around 70% of my scripts).

It is a thing of being "used to".

But I say it again, Bn808 and you are right, it is easier for ppl in general and they should stick to it (so forget what I wrote . But I am an waisted old bastard scripters who wont change his way of scripting in his old days (maybe I do, dunno yet).

Other good practice: Use a "clear" variable name. This way it becomes easier to read the code when you have to look through it some month later (or in case someone else look into your script). I think that a clear variable name even justifies a longer name (ok: _i is really often used for _index, I do it myself, so lets keep that;)

Share this post


Link to post
Share on other sites

Yes a legible variable name is often better than the one character counterpart for legibility reasons, but in most scriptswhich are released as addons I now think it is better to maximally shorten _everything_ once testing has been completed, in order to save everyone using the addon CPU cycles. I am talking one line functions, one character variables and labels.

Maintenance has to be seperated from runtime since there is no compiler. On the other had for custom scripts that run one per entire mission it may be easier to leave the script legible.

I also used to try making scripts legibe, but after doing more extensive research into performace issues I am of a different opinion.

EDIT: Oh and what would you feel like if you knew for example the Network services or UA have very legible variable names and functions. (as a mission designer, or someone who is playing at 15fps already) You would not be pleased that the scripts are not maximally shortened to save CPU usage.

Share this post


Link to post
Share on other sites

Is there a program for optimising OFP scripts?

Some thing that breaks down variables and labels. like Chris's OFP Script Editor? You should be able automate the process of optimising things like variable names e.t.c.

Share this post


Link to post
Share on other sites

Well, I heard of Rubble_Maker making a PreProcessor that shortens stuff. Have not heard anything from him in a while though, but he was always big on this optimization stuff. smile_o.gif

EDIT: Personally I don't mind shortening scripts via search/replace or regex(actually I would have some problems with a preProcessor most likely).

Share this post


Link to post
Share on other sites

Unless it is automated, I doubt I would bother optimising anything substantial.

For me its rare entire scripts require every drop of processing power. It's usually just certain sections, if at all.

A single pass, error free conversion process to convert all the user friendly variable names to _A _A1 _A2 e.t.c for release, would be a practical solution.

Share this post


Link to post
Share on other sites

Doesn't matter if your scripts don't require that, you may be working along side 100-1000 other scripts if you release an addon. smile_o.gif

Share this post


Link to post
Share on other sites

One thing to keep in mind for making faster scripts is to utilize sqf files and the call command whenever possible.

It's my understanding that these sqf files are compiled only once at mission load and remain in memory unlike sqs scripts.

You need to keep the sqf short and to the point as well. Sqf files run at the speed of the processor and do not recognize any time delays or @ statements. You need to integrate sqs and sqf files for best performance if you want to have timed events.

Share this post


Link to post
Share on other sites

currently .sqf files are compiled at runtime like anything else.

And I suspect that the entire mission directory is loaded into memory when playing a mission (as opposed to editor preview).

.sqf and .sqs files serve complementary purposes.

if you call a function (.sqf files), the whole function is treated as a single line of a script, and is run immediately. The function terminates before you can proceed to the next line of a script.

if you exec a script, the script starts up in a separate thread.

Some things work better in functions. Others need scripts (gotos, ~, @ and similar functions cannot work in a function). And some won't work too well in a pure function (such as Bn880's cruise missile pathing system. If he ran that in one function, OFP would freeze for something like 30 seconds causing one hell of a stutter)

Share this post


Link to post
Share on other sites
Quote[/b] ]Doesn't matter if your scripts don't require that, you may be working along side 100-1000 other scripts if you release an addon.

True, but I have no control over who uses addons\scripts or how many, or what they use them for. If I was worried about that I would probably not release anything.

You can only spec things based on what you would consider being a reasonable mission by our OFP peers.

If you are talking about talking a couple of seconds of a loop that takes 5 second?. Then I will write an optimizer myself.

If its the difference of allowing somwone to run 999 scripts rather than 989 then I'd just suggest they dont use that script or addon, or optimize there own code smile_o.gif

Share this post


Link to post
Share on other sites

Questions:

1) Has nil some positive effect on memory usage? Is it usefull command? (deleting of unusefull variables)

2) Is it useful to delete triggers (via deleteVehicle triggerName) that are no longer needed during mission?

3) Is script example A better then example B?

example A:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;init part here:

;e.g. createUnits and createVehicles

;placement of units,

;their behaviour and

;combatMode ...

...

;repeating part of script here

;e.g. loop checking position or status of units ...

example B:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call loadfile "init part elsewhere.sqf"

...

;repeating part of script here

4)What is better? To A)run several (10+) small scripts simultaneously or B)only one that uses array?

exaple of small script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit=_this select 0

#loop

~5

?alive _unit:goto "loop"

hint format ["%1 destroyed",_unit]

exaple of sript with array:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_units=_this select 0

#loop1

_i=count _units

?_i<=0:exit

#loop2

~1

_i=_i-1

_unit=_units select _i

?!(alive _unit):goto "dead"

?_i>=1:goto "loop2"

goto "loop1"

#dead

hint format ["%1 destroyed",_unit]

_units=_units-[_unit]

goto "loop1"

I think it's 1)yes; 2)yes; 3)B; 4)B

but I'm not sure.

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  

×