A Question about Arrays?

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

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

BabyFace
Posts: 140
Joined: Sat, 24. Jan 04, 23:06
x2

A Question about Arrays?

Post by BabyFace » Tue, 23. Mar 04, 06:25

hi ya'll,

i have recently been learning (albeit) slowly about arrays and have a question.


Say if i create a seperate script and call it "Components Array", it contains all the "components" that a ship can use in this array. Also it contains the appropiate "prices" based on the "get max price" of ware.

It preforms all the correct calculations for the "ware/price" and "need/have" compared with the "selected" ship.

Currently i can pass the "total" required price back to my "call" script so I can tell what it will cost to upgrade my ship with the missing components.

I say all that to ask this:

Is it possible to "pass" from the array (being that it has done all the calculations already) the "needed" components back to the "call" Script so i can install the missing components based on the arrays info, or must I continue as below: (current setup)

Code: Select all

006   if $PackageNumber == 1
007    $total = 0
008 @  $cost = [THIS] -> call script 'plugin.BF.component.values' :  Select Ship to Check=$Ship  Selected Upgrade Package=$PackageNumber
Then the calculations are preformed to see if the player has the appropiate credits to preform the "requested" upgrades, if player is short they get a msg, if player has enough the get the following:

Code: Select all

else
018     $Guild = $Ship -> install 1 units of Best Buys Locator
019     $Guild = $Ship -> install 1 units of Best Selling Price Locator
020     $Guild = $Ship -> install 1 units of Boost Extension
021     $Guild = $Ship -> install 1 units of Duplex Scanner
022     $Guild = $Ship -> install 1 units of Ecliptic projector
023     $Guild = $Ship -> install 1 units of Fight Command Software MK1
024     $Guild = $Ship -> install 1 units of Fight Command Software MK2
025     $Guild = $Ship -> install 1 units of Freight scanner
026     $Guild = $Ship -> install 1 units of Mineral Scanner
027     $Guild = $Ship -> install 1 units of Navigation Command Software MK1
028     $Guild = $Ship -> install 1 units of Special Command Software MK1
029     $Guild = $Ship -> install 1 units of Trade Command Software MK1
030     $Guild = $Ship -> install 1 units of Trade Command Software MK2
031     $Guild = $Ship -> install 1 units of Trading system extension
032     $Guild = $Ship -> install 1 units of Video Enhancement Goggles

from this example is it possible to make all those "installs" to just 1 install command via the array like:

Code: Select all

$Guild = $Ship -> install $requestedAmount units of $TheWare
I realize i am already passing back to the call script the "total" for the upgrades but can i at the same time pass back the "needed components"?

Any help is greatly appreciated, Thanks for your time.
Check Regularly for new Script/Mods
http://www3.telus.net/public/starnet/default.htm

At the top of each page is a "Back To Main Page" Link

BabyFace

AalaarDB
Posts: 2282
Joined: Thu, 29. Jan 04, 08:19
x3tc

Post by AalaarDB » Tue, 23. Mar 04, 07:07

Get the size of needed comp array, make a loop with
while size >=0
specific comp = needed comp[size]
install SC
dec size

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Tue, 23. Mar 04, 07:20

hmm, I would make three parallel arrays, one for the items, one for the cost, and a final boolean array for whether or not the ship has the upgrade.

When your script runs, it would first check your ship for what upgrades it has, and place a TRUE to the boolean array. then it could run through the boolean array to sum the cost and then finally to install the components.

I dont know the exact commands but maybe this model

stuffarray
costarray
needarray

(filled and sized appropriately)

i=0
while i<sizearray
item =stuffarray
needit=<currentship> -> get true amount of ware 'item'
if needit == 0
needarray = TRUE
else
needarray = FALSE
end
inc i =
end

x=0
totalcost=0
while x<sizearray
if needarray[x]==TRUE
itemcost=costarray[x]
totalcost+=itemcost
end
inc x=
end

y=0
while y<sizearray
if needarray[y]==TRUE
item = stuffarray[y]
retvar = <currentship> add 1 unit of ware 'item'
end
inc y=
end
subtract 'totalcost' from players money


TW

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