Scripting Checklist

The place to discuss scripting and game modifications for X²: The Threat.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

User avatar
moggy2
Posts: 5505
Joined: Wed, 6. Nov 02, 20:31
x3ap

Scripting Checklist

Post by moggy2 »

http://www.xai-corp.net/node/73

I'm putting together a checklist of things to concider when writing scripts, to help remember all the possibilities and unusual situations that scripts need to be able to cope with. I figured others would find it useful, especially if they're thinking of trying to get their scripts signed.

It's a wiki style page where anyone can edit the contents, so if you see something I've missed you can add it yourself

It currently looks like this:
Scripting Checklist wrote: When writing scripts there are many things you need to keep in mind about how the script will interact with the X-Universe. It's not enough that the script functions properly in the ideal circumstances that it was designed for, it must also be able to cope with the unexpected.
It is the nature of the X-Universe that if there is the possibility of something happening it will happen to someone. Your scripts need to be abe to handle every possibility without causing a problem (ie. crashing)

The Following is a checklist of things that you should think about when writing your scripts:

General
-Always concider how the script will react if it is called by a foreign script by someone else. Will it cope if the parameters are screwed up, or missing?

Navigation
-Make sure you get there. All navigation commands are interuptable. If they get interupted by another script they will stop before they've reached their destination.
Using a while loop to make sure you've arrived is a good idea, but you need to watch out for potential problems with the target
--Can you actually get to that sector?
--Can you dock at that target?
--Does the target still exist, has it been destroyed?
--Has the target turned hostile, or was it supposed to be an enemy?

Trading
-Are you actually docked?
-Are you docked at the right place?
-Is the price still right?
-do you have enough money?
-can you carry that type of cargo?
-can you carry that much?
You can edit it here
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

not a bad idea :)
There are a lot of things that most would consider silly that we have to do to scripts before we can sign them.
Starting a list of good scripting practices is a nice step in the right direction.
I'll link this from the resources thread.
Everyone feel free to put good scripting practices on the wiki.

It might be a good idea to put sample code on the wiki as well.
For example:


- can you actually get to that sector?
  • This is something people often don't check for before issuing a move command. You have to realize that the khaak sectors are selectable, but cannot be reached without special jumping. Also, in some custom universes, sectors may not be connected to eachother. The following code (or something like it) addresses this concern:

    Code: Select all

    if $sector.one != $sector.two
      if not get jumps from sector $sector.one to sector $sector.two
        (send an error message to player)
        return null
      end
    end
    
    get jumps from sector to sector will return a null if there is no possible path.
    In the above code, we first make sure that number of jumps != 0 with the first statement, since that would trigger a false positive for no pathfinding in the second if statement if number of jumps was 0. Then we check if there is a possible path. If not, the code in the if statement executes since the get jumps command will return null.
A checklist with example code would go a long way to stamping out common bugs if people used it.
Cheers.

ps. tried putting that on the wiki, didn't do an excellent job formatting it :(
"Nature's first green is gold" . . . stay golden.
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

combat related scripts

-is the target docked or not (have had a bunch a CTD cause I forgat about that one)




G

Return to “X²: The Threat - Scripts and Modding”