EnglishGermanFrenchRussianPolishItalianSpanish
Log inRegister
 
[WiP]Syntax - Editor - Etiquette
Post new topic Reply to topic
View previous topic :: View next topic
Author Message
Orfevs





Joined: 23 Jan 2009
Posts: 165 on topic

Thank you for registering your game
modified
PostPosted: Fri, 13. Apr 12, 22:38    Post subject: [WiP]Syntax - Editor - Etiquette Reply with quote Print

..or how to handle yourself in a script.

-- WiP -- I expect every vigilant scripter to pit in here Wink -- 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:
    $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:

    $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:
    * Good:
    set global variable: name="yourstruly.myScript.weaponarray" value= $weapon.array
    * Bad:
    set global variable: name="array" value= $weapon.array





Last edited by Orfevs on Sat, 28. Apr 12, 04:41; edited 1 time in total
Back to top
View user's profile Send private message
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)

MEDALMEDALMEDAL

Joined: 02 Apr 2006
Posts: 19748 on topic

Thank you for registering your game
PostPosted: Fri, 20. Apr 12, 16:50    Post subject: Reply with quote Print

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.


_________________
Ab sofort verfügbar: Farnhams Legende und Nopileos als E-Books!

"People who think they know everything are a great annoyance to those of us who do." - Isaac Asimov
Back to top
View user's profile Send private message Visit poster's website
Orfevs





Joined: 23 Jan 2009
Posts: 165 on topic

Thank you for registering your game
PostPosted: Sat, 28. Apr 12, 04:45    Post subject: Reply with quote Print

Added


_________________
TCAN TC/AP Artificial Life, Menudriven Automated Ship/Station Namer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic Reply to topic
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Sat, 25. Mar 17, 19:35

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.19845 seconds, sql queries = 17