Basic Scripting help
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
-
- Posts: 164
- Joined: Wed, 31. Dec 03, 20:39
Basic Scripting help
Lets pool our collective knowledge until the documentation is released
Constants seem a good place to start, I think I know what they mean, any corrections welcome:
[TRUE] : True..
[THIS] : RefObject running the script
[SECTOR] : Current Sector of RefObject
[PLAYERSHIP] : Player's Ship
[OWNER] : RefObj's Race
[HOMEBASE] : RefObject's Homebase
[ENVIRONMENT] : Location of RefObject (Sector/Ship/Station)
[DOCKEDAT] : Where RefObj is Docked
[FALSE] : False...
Constants seem a good place to start, I think I know what they mean, any corrections welcome:
[TRUE] : True..
[THIS] : RefObject running the script
[SECTOR] : Current Sector of RefObject
[PLAYERSHIP] : Player's Ship
[OWNER] : RefObj's Race
[HOMEBASE] : RefObject's Homebase
[ENVIRONMENT] : Location of RefObject (Sector/Ship/Station)
[DOCKEDAT] : Where RefObj is Docked
[FALSE] : False...
Last edited by Sgt. Dubious on Tue, 20. Jan 04, 18:19, edited 1 time in total.
-
- Posts: 164
- Joined: Wed, 31. Dec 03, 20:39
Arrays: How to define/use
When using a group select command, you have to use an Array to to access the assembled data.
Ex:
(Everything in red is user definable)
From the General Objects Command set:
$ShipGroup = find ship: sector= null class or type= null race= Player flags= [Find.Multiple] refobj= null maxdist= null maxnum= 999 refpos= null
From the General Commands -> Arrays set:
$ShipTotal = size of array $ShipGroup
Assigns the variable "ShipTotal" to represent the total number of entries in the Array "ShipGroup" as an integer.
Next from General Commands you set a counter to determine the place in that array:
$ShipID = 0
Now lets start out mass order loop, create a Label to define this
OrderLoop (For example)
From the GC set
If $ShipID < $ShipTotal
The Following commands will be contained in this IF statement until you tell it to end.
From GC -> Arrays
$CurrentShip =$ShipGroup [$ShipID]
The variable CurrentShip now represents the ship in position $Ship (currently 0) in your array of the ShipGroup data.
You may now execute any number of commands for $Ship in this loop
{Some sort of command}
At the end of the commands do as follows (GC Command set)
$ShipID = $ShipID +1
goto label OrderLoop
end
The last 3 lines increase the ShipID to be used by one, moving to the next ship in your list. At the beggining of the Loop, it checks to see that ShipID is less than ShipTotal. If you have 10 ships, then that array is 10, the ShipID for those entries will be 0-9. So as long as it is less than 10, we know the ship actually exists.
There may be a more efficient way to do this, but I havent figured it out yet, or seen a 3rd party script that used it. Input is of course, still welcome.
[Edit: Fixed, thanks Moggy]
When using a group select command, you have to use an Array to to access the assembled data.
Ex:
(Everything in red is user definable)
From the General Objects Command set:
$ShipGroup = find ship: sector= null class or type= null race= Player flags= [Find.Multiple] refobj= null maxdist= null maxnum= 999 refpos= null
From the General Commands -> Arrays set:
$ShipTotal = size of array $ShipGroup
Assigns the variable "ShipTotal" to represent the total number of entries in the Array "ShipGroup" as an integer.
Next from General Commands you set a counter to determine the place in that array:
$ShipID = 0
Now lets start out mass order loop, create a Label to define this
OrderLoop (For example)
From the GC set
If $ShipID < $ShipTotal
The Following commands will be contained in this IF statement until you tell it to end.
From GC -> Arrays
$CurrentShip =$ShipGroup [$ShipID]
The variable CurrentShip now represents the ship in position $Ship (currently 0) in your array of the ShipGroup data.
You may now execute any number of commands for $Ship in this loop
{Some sort of command}
At the end of the commands do as follows (GC Command set)
$ShipID = $ShipID +1
goto label OrderLoop
end
The last 3 lines increase the ShipID to be used by one, moving to the next ship in your list. At the beggining of the Loop, it checks to see that ShipID is less than ShipTotal. If you have 10 ships, then that array is 10, the ShipID for those entries will be 0-9. So as long as it is less than 10, we know the ship actually exists.
There may be a more efficient way to do this, but I havent figured it out yet, or seen a 3rd party script that used it. Input is of course, still welcome.
[Edit: Fixed, thanks Moggy]
Last edited by Sgt. Dubious on Tue, 20. Jan 04, 18:17, edited 1 time in total.
-
- Posts: 164
- Joined: Wed, 31. Dec 03, 20:39
Checking your script, quick way to verify variables:
A simple logbook command is currently the easiest way I've found to verify that my variables are recording the proper data. Periodically, either through mis-referencing or misunderstanding the target of a "get" statement, they wind up recording the wrong thing.
To do this, select the "write to player logbook: sprintf: fmt=" command from the Logbook Commands menu. Then just tell it to display the variables you're checking. The first entry is a String, the next 5 are Variables which you will reference in that String. It should read:
write to player logbook: sprintf: fmt= 'Var1 %s Var2 %s Var3 %s Var4 %s Var5 %s', $Var1, $Var2, $Var3, $Var4, $Var5
The output will replace the "%s" with the next variable in the chain. You could just set the string to '%s %s %s %s %s' but you might forget which variable is what, so you may want to label them.
A simple logbook command is currently the easiest way I've found to verify that my variables are recording the proper data. Periodically, either through mis-referencing or misunderstanding the target of a "get" statement, they wind up recording the wrong thing.
To do this, select the "write to player logbook: sprintf: fmt=" command from the Logbook Commands menu. Then just tell it to display the variables you're checking. The first entry is a String, the next 5 are Variables which you will reference in that String. It should read:
write to player logbook: sprintf: fmt= 'Var1 %s Var2 %s Var3 %s Var4 %s Var5 %s', $Var1, $Var2, $Var3, $Var4, $Var5
The output will replace the "%s" with the next variable in the chain. You could just set the string to '%s %s %s %s %s' but you might forget which variable is what, so you may want to label them.
[nitpick] ShipGroup is the array containing the ship objects returned from the findship function. ShipArray is an integer whose value is equal to the number of elements in the array ShipGroup. [/nitpick]Sgt. Dubious wrote:$ShipGroup = find ship: sector= null class or type= null race= Player flags= [Find.Multiple] refobj= null maxdist= null maxnum= 999 refpos= null
From the General Commands -> Arrays set:
$ShipArray = size of array $ShipGroup
This creates an Array "ShipArray" to hold the ship data you assigned to the variable "ShipGroup"
-
- Posts: 164
- Joined: Wed, 31. Dec 03, 20:39
Well that makes a hell of a lot more sense, thanks I've been reading backwards I guessMehrunes wrote:[nitpick] ShipGroup is the array containing the ship objects returned from the findship function. ShipArray is an integer whose value is equal to the number of elements in the array ShipGroup. [/nitpick]
[Edit] I'll edit in the change later. Its sunday, Im lazy
Sorry to hijack a thread but I thought this might be relevant
I've started a wiki on Xai Corporation devoted to the tips and tricks of
writing scripts for X2. It's under the module name of Scripting Handbook.
If you're not aware of what a Wiki is, it's a means to allow users to edit
a webpage to add their own content, building on what is already there. I'm
hoping the people writing scripts at the moment will be able to create a
hand book of how to do scripting by each sharing a small part of their own
knowledge.
At the moment there's not much there, ok that's an understatement, but if
we all chip in a fact or two, something we've descovered for ourselves,
then we can all make it into something useful as more people get into
scripting before the official documents are available.
I've started a wiki on Xai Corporation devoted to the tips and tricks of
writing scripts for X2. It's under the module name of Scripting Handbook.
If you're not aware of what a Wiki is, it's a means to allow users to edit
a webpage to add their own content, building on what is already there. I'm
hoping the people writing scripts at the moment will be able to create a
hand book of how to do scripting by each sharing a small part of their own
knowledge.
At the moment there's not much there, ok that's an understatement, but if
we all chip in a fact or two, something we've descovered for ourselves,
then we can all make it into something useful as more people get into
scripting before the official documents are available.