Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (added use comments)
m (tiny update)
Line 12: Line 12:


=== Make it readable ===
=== Make it readable ===


{{Informative | See [[Code Optimisation#Make it readable|Make it readable]] for the short version!}}
{{Informative | See [[Code Optimisation#Make it readable|Make it readable]] for the short version!}}
Line 25: Line 24:
** Format, indentation, no one-line, spacing, line returns
** Format, indentation, no one-line, spacing, line returns
** Be consistent (space/tab indentation, (camel)casing, [https://en.wikipedia.org/wiki/Indentation_style#K&R_style K&R style] / [https://en.wikipedia.org/wiki/Indentation_style#Allman_style Allman style] indenting)
** Be consistent (space/tab indentation, (camel)casing, [https://en.wikipedia.org/wiki/Indentation_style#K&R_style K&R style] / [https://en.wikipedia.org/wiki/Indentation_style#Allman_style Allman style] indenting)
* Use comments frequently to explain what the code does.
* Use comments frequently to explain ''not'' what the code does, but ''why'' it is done this way.


=== Make reusable functions ===
=== Make reusable functions ===


* Don't duplicate, make functions
* Don't duplicate, make functions
* Don't make macros to replace SQF code


=== Variables ===
=== Variables ===
Line 40: Line 40:


* '''Nothing''' in init box ''but'' [[local]] commands for this specific unit - '''all''' the init boxes are run client-side on client connection
* '''Nothing''' in init box ''but'' [[local]] commands for this specific unit - '''all''' the init boxes are run client-side on client connection
* {{Inline code|'''0 {{=}}''' ''myCommand''}} is "useful" only for editor fields that for no apparent reason refuse commands returning a value.
* {{Inline code|<span style{{=}}"background-color: #FCC">'''0 {{=}}''' </span>''myCommand''}} is "useful" only for editor fields that for no apparent reason refuse commands returning a value.




== Final words ==
== Final words ==


* Don't steal code and pretend it's yours — be a decent human being.
* Learn from others' scripts but don't steal code and pretend it's yours — be a decent human being.
* Don't try to obfuscate your code: it's considered rude, especially since you learnt from others.
* Don't try to obfuscate your code: it is considered rude, especially since you learnt from others.
* Have fun!
* Have fun!

Revision as of 22:22, 6 September 2019

this is at the moment only a list of topics and absolutely not the final render. Almost each list entry will result in a chapter.




Category: Scripting Topics

Best practices

Make it readable

See Make it readable for the short version!
  • Some general coding tips from here: standards, line lengths, etc
    • Variable names should indicate what they store / are used for.
Example

// Instead of private _cd = 360; // do private _countDown = 360;

    • Format, indentation, no one-line, spacing, line returns
    • Be consistent (space/tab indentation, (camel)casing, K&R style / Allman style indenting)
  • Use comments frequently to explain not what the code does, but why it is done this way.

Make reusable functions

  • Don't duplicate, make functions
  • Don't make macros to replace SQF code

Variables

  • Prefix your public variables and setVariable with your tag
  • PRIVATE (or params) your variables
  • Use #define SOME_CONST for constant values instead of variables

Code location

  • Nothing in init box but local commands for this specific unit - all the init boxes are run client-side on client connection
  • 0 = myCommand is "useful" only for editor fields that for no apparent reason refuse commands returning a value.


Final words

  • Learn from others' scripts but don't steal code and pretend it's yours — be a decent human being.
  • Don't try to obfuscate your code: it is considered rude, especially since you learnt from others.
  • Have fun!