code from Scripting Guide don't work?

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

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

User avatar
Kailric
Posts: 985
Joined: Sun, 7. Dec 03, 05:15
x3

code from Scripting Guide don't work?

Post by Kailric »

I typed up this code from the Scripting Guide but I can't seen to get it to work..anyone know whats up? The $size of array never returns a value ?

001 $target = find ship: sector=Atreus' Clouds class or type=Moveable Ship race=Pirates Flags=[Find.Multiple] refobj=[THIS] maxdist=null maxnum=null refpos=null
002 $count = 0
003 $size = size of array $target
004 while $count < $size
005 $result = $target[$count]
006 $count = $count + 1
007 write to player logbook $result
008 end
009
010 return null
"Try not. Do or do not, there is no try."-Yoda

"[Its] time for the human race to enter the solar system"-Dan Quayle
User avatar
Kailric
Posts: 985
Joined: Sun, 7. Dec 03, 05:15
x3

Post by Kailric »

I Searched the site and found this..it solved my problem..you have to set a maxnum in the find ship command or it want return an array..yippie :D
Sgt. Dubious wrote: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]
"Try not. Do or do not, there is no try."-Yoda

"[Its] time for the human race to enter the solar system"-Dan Quayle

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