[WiP]Syntax - Editor - Etiquette

This forum serves as MSCI Reference at EGOSOFT. It's Read-Only for non MSCI Group members.

Moderators: Scripting / Modding Moderators, MSCI Moderators

Post Reply
Orfevs
Posts: 183
Joined: Thu, 22. Jan 09, 23:03
x3tc

[WiP]Syntax - Editor - Etiquette

Post by Orfevs »

..or how to handle yourself in a script.

-- WiP -- I expect every vigilant scripter to pit in here ;) -- WiP --
  • Provide an Author and Date of creation/last edited, and optionally a means to get in touch. Email, website, forum.
    Looking through your favorite scripts from way back, you find a plugin, and you don't know what it does, who made it, or why the readme didn't provide an author. The scripts are gibberish, and what name you could make out was "sprintf". Who in the abyss is sprintf? Oh wait.. no. Perhaps that was a command?
  • External/Internal changelog.
    Knowing what was fixed might give you a star with the user of your script. Also, when returning to your scripting after a long absence, it's good to have as much info as possible so you know what you were doing in the first place.
  • Naming Conventions
    To improve the readability for your own benefit as well as others, it is a good thing to use descriptive names.

    Code: Select all

    $a1 = $a2 -> get name
    * versus this
    $ship.name = $ship.reference -> get name
    
  • Reuse variables
    Reusing variables rather than creating new ones should save memory. The more scripts you cram into your game, the more memory it uses. Hence it's a good practice to have variables you can use repeatedly as each new variable eats a bit of memory

    Code: Select all

    $loop = 10
    while $loop
       dec $loop =
       ...
    end
    
    ...
    
    $loop = 0
    while $loop < 15
       ...
       inc $loop =
    end
    
  • Comment
    To further improve readability, use comments, if only to separate sections of your script. A simple dashed line can make a huge difference in the script's appearance
  • Unique Global Variables
    Global variables are just that - global. Which means any script can access them as long as the name is known. That's why it's a good idea to use the script's name and author in the variable to ensure it is unique. Otherwise you might accidentally trample on another script.

    Code: Select all

    * Good:
    set global variable: name="yourstruly.myScript.weaponarray" value= $weapon.array
    * Bad:
    set global variable: name="array" value= $weapon.array
    
    [/size]
Last edited by Orfevs on Sat, 28. Apr 12, 04:41, edited 1 time in total.
User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 25043
Joined: Sun, 2. Apr 06, 16:38
x4

Post by X2-Illuminatus »

I think using comments should also be listed here as well as naming conventions of variables, i.e. don't name your variables "$a1", "$a2", "$a3" etc., but use names that describe the kind of info that you want to store in it ("$ship" for a ship, "$station" for a station etc.). That increases the readability of a script, for the author as well as for anyone who wants to read/change it someday. Also in case more than one scripter is working on the same script file(s), it's a good idea to maintain a little changelog directly in the script.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!
Orfevs
Posts: 183
Joined: Thu, 22. Jan 09, 23:03
x3tc

Post by Orfevs »

Added
TCAN TC/AP Artificial Life, Menudriven Automated Ship/Station Namer
Spex: i7 4790K@4Ghz 16Gb DDR3 GTX970Strix(4Gb)
X:R 454 Hours. 15 hours unmodded.
Post Reply

Return to “MSCI Reference”