Transcendence Scripting questions

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
dvlenk6
Militia Captain
Militia Captain
Posts: 519
Joined: Sun Mar 05, 2006 6:56 am
Location: Sanctuary and beyond
Contact:

For George, I guess, unless somebody else knows.

1) Can you use concatenations for variable names and,
2) Is there some way to make a for/next loop, or something similar to it.
3) Does a Data array (like the sisters of domina donation table) have to be inside of the staticdata of a station or can it be used globally too? I seem to remember seeing it globally, but now I can't find it. Maybe I just dreamed about that. :P
4) Can an extension be made to write information or is it read only?

Most of that is about sorting some lists.
#4 is out of sheer curiosity
"War is hell."
-William Tecumseh Sherman
http://dvlenk6.blackraven3d.com/transgals.html
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

1) If C can't do it, this scripting language can't, so I doubt it.
2) Search for Enum, that is the closest I've found. Other than that, if you are working in a dockscreen, looping through the same <action> will work (though it is more like a goto loop than a for/next)
3) Anything single item can be declared globally as far as I can tell, but not arrays. Globally declare items seem to just be text and a value.
4) An extension can do almost anything the base xml files can do, and I don't think they can write.
User avatar
dvlenk6
Militia Captain
Militia Captain
Posts: 519
Joined: Sun Mar 05, 2006 6:56 am
Location: Sanctuary and beyond
Contact:

O.k. Thanks.
I'm only 'fluent' with perl.
There are very many differences between that and this scripting language.
Don't know much about C.

I would be very lost without that function list that George posted a while back.

EDIT - I found the for/next, oddly enough it was in one of my own mods that I saw it again :shock: It is:
(for i 1 6
...
)
"War is hell."
-William Tecumseh Sherman
http://dvlenk6.blackraven3d.com/transgals.html
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Hmm, I missed the for loop too, sorry I rushed the answer a little.

As to storing data arrays, look at the code for the mission to transport grain. Part of that mission removes and stores the player's cargo. That part you are interested in is:

(objSetData gSource "fleetMissionSavedCargo" (setq allItems (objGetItems gPlayerShip "*U~m -ID;")))

which sets the slot "fleetMissionSavedCargo" equal to what I assume is an array of item IDs.

It isn't as flexible as a static data set, but static data is treated more like its own tag in the xml, instead of like a data array.
User avatar
dvlenk6
Militia Captain
Militia Captain
Posts: 519
Joined: Sun Mar 05, 2006 6:56 am
Location: Sanctuary and beyond
Contact:

I saw that xml bit.
That is stored with gSource, the station, I believe.
I think I should be able to put a similar data type expression in gPlayerShip?
Would objSetData be the best way to do that?
or would objSetGlobalData or objSetObjRefData be better in this case? :?

I want it too be as globally accessible as possible.
"War is hell."
-William Tecumseh Sherman
http://dvlenk6.blackraven3d.com/transgals.html
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

1. You can use concatenations for variable names for (objSetData ...). For example, check out the code for creating wingmen:

Code: Select all

for i 0 (subtract aCount 1)
   (block (ship)
      (setq ship (sysCreateShip &scCenturion; aStation &svCommonwealth; "fleet"))
      (shpOrderEscort ship gPlayerShip i)

      ; Remember the escorts we assigned
      (objSetObjRefData aStation (cat "Wingman" i) ship)
      )
   )
Notice that the (objSetObjRefData ...) call uses a concatenation of "Wingman" and the loop variable (i) to store each wingman.

2. Looks like you already figured out the syntax for a loop.

3. You can put a data array anywhere. The only constraint is that you cannot have arrays of objects (gStation, for example). That is the reason why there is a separate call for storing objects.

If I want to remember an array, I could do this:

Code: Select all

(objSetData gSource "NumbersFrom1To8"
   '(1 2 3 4 5 6 7 8)
   )
(You need the quote in front of the array to signify that this is data and not a call to a function called "1")

But if I want to remember a list of objects, then I CANNOT do this

Code: Select all

(objSetObjRefData gSource "MyShips"
   '(ship1 ship2 ship3 ship4)  ; *WRONG*
   )
Instead I need to use the technique I used with wingmen above.

One more thing:

(objSetData ...) attaches data (not objects) to an instance of an object. For example, you might use it to attach data to an INSTANCE of a Tinker station (each Tinker station has different data).

(objSetGlobalData ...) attaches data (not objects) to the class of an object. For example, you might use it to attach data that applies to all Tinker stations. No matter which Tinker station you go to, you will always get the same data.

(staSetGlobalData ...) is the same as the above except that it takes a station type instead of an object pointer. Instead of:

(objSetGlobalData gSource ...)

You can use:

(staSetGlobalData &stTinkerGathering; ...)

[If gSource happens to be a Tinker station, both calls are identical.]

(objSetObjRefData ...) is only used to attach object references to an INSTANCE of an object. There are no equivalents for global data (i.e., there is no way to store an object reference in global data).
User avatar
dvlenk6
Militia Captain
Militia Captain
Posts: 519
Joined: Sun Mar 05, 2006 6:56 am
Location: Sanctuary and beyond
Contact:

I read right over that same wingmen concatenation xml at least twice and didn't recognize as such :oops: .

Thanks for clearing all of this up. I never had come to understand the difference between the different objSet... :D
"War is hell."
-William Tecumseh Sherman
http://dvlenk6.blackraven3d.com/transgals.html
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

George, is there any way to pull a specific element out of a stored array? In the example you gave, how could I get only the 3rd element without enum'ing the whole set?

Also, to be precise, you aren't really concatenating variable names, those are the string identifiers that are being concatenated. That wouldn't work so well with a setq.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

To access the 3rd element in the array you can use the (item ...) function. The syntax is:

(item someArray 2)

Where 2 is the 0-based index of the element that you want to access.

You are right about the bit about concatenating variables. You can't do that with (setq). But you can use a different function: (set)

(set (cat "Wingman" 5) "Hello")

is supposed to be the same as

(setq Wingman5 "Hello")

However, I've never tried it, so I have no idea if it will work or not.

In Lisp, (setq) is just a wrapper on top of (set). (set) evaluates all its parameters before assigning the variables, thus it evaluates the (cat) function and uses the result as the variable name.

(setq) has an implied quote (') in front of the first argument. Thus:

(setq Wingman "test")

is really evaluated as:

(set 'Wingman "test")

The quote in front of Wingman means, "treat the string 'Wingman' as a literal--do not try to evaluate it" No points for quessing what the "q" in "setq" stands for.

Since I based the Transcendence scripting language on Lisp, I decided to implement both (set) and (setq) but in practice I've never used (set).

Lisp is extremely powerful, but as you can see, it is also extremely hard to understand. In retrospect, I should have based the scripting-language on something else.
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Ahh, I see. C and JAVA have always been my strong suits, I never had the urge to look too deeply into scripting languages, aside from were my job requires.

I've always been a fan of declaring my variables, concatenated variable names reminds me of SIMAN enough to give me the chills.

That said, I don't have any specific complaint about the scripting language other than the vague lack of docmentation :wink: Of course being able to use nice clean JAVA classes would be sooooo much easier :wink: but if I remember correctly the folks you work for have a nasty aversion to coffee :roll:
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Sorry to double post,

George, is there a way to modify elements of an array? For example, I am trying to set each element of an array with a set of odds in a mod the code I am using is:

Code: Select all

(for i 0 14
    (setq (item odds i) (intRaceOdds (sTotal (item skills i))))
    )
Since setq needs an actual variable to work on, this isn't working. It seems like I need a function similiar to aset to set the individual elements of the array.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Try:

Code: Select all

   (lnkReplace someList index value)
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Ah, much better. Arrays still handle like shopping carts, but at least they are shopping carts with wheels now :wink:

On that note, here is an abomination I created to handle dealing the first 4 cards in a blackjack game:

Code: Select all

(setq card1 (random 1 13))
(setq card2 (random 1 13))
(setq card3 (random 1 13))
(setq card4 (random 1 13))
(setq playerCards '(0 0 0 0 0 0 0 0))
(setq dealerCards '(0 0 0 0 0 0 0 0))
(lnkReplace playerCards 0 card1)
(lnkReplace playerCards 1 card2)
(lnkReplace dealerCards 0 card3)
(lnkReplace dealerCards 1 card4)
Honestly, coding like that makes me feel dirty, like I should be drawing pictures of bison on a wall with charcoal, but I can't seem to find a way to get functions to resolve before array declarations. For example, originally, instead of the above, I simply had:

Code: Select all

(setq playerCards '((random 1 13) (random 1 13)))
(setq dealerCards '((random 1 13) (random 1 13)))
But I couldn't get the (random) sections to evaluate before the '() function!
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Burzmali wrote:But I couldn't get the (random) sections to evaluate before the '() function!
Doh! Sorry--here are a couple of more list functions:

(list a b c d e f)

returns a list consisting of (a b c d e f) where all the elements have been evaluated.

(lnkAppend list element)

appends the element to the given list.

Hope that helps!
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Okay, okay, less like a shopping cart and more like a Winnebago now ;)

So, data arrays are being treated like a list of some kind. Any chance you implemented a "remove" function of some kind? I am trying to draw 5 items from a list of 15, and I am trying to ensure that there are no repeats. If can detect duplicates in a test item, but I can't seem to affect the count.

(for i 0 4)
...
(if duplicate
(setq i (subtract i 1))
)
)

As far as I can tell, all of this is designed to prevent the creation of an infinite loop, but it does make for some annoying work arounds.

Here is the code I am working with:
(block (pilots racers i)
(setq pilots (objGetData gSource "pilots"))
(setq racers '('("pilot1" 0) '("pilot2" 0) '("pilot3" 0) '("pilot4" 0) '("pilot5" 0)))
(for i 0 4
(block (testPilot testRacer newPilot)
(setq testPilot (random pilots))
(setq newPilot 1)
(enum racers testRacer
(if (eq (item testRacer 0) (item testPilot 0))
(setq newPilot 0)
)
)
(if (eq newPilot 1)
(lnkReplace racers i testPilot)
(setq i (subtract i 1))
)
)
)
Ideally, I would like to be able to write it like this:
(block (pilots racers i)
(setq pilots (objGetData gSource "pilots"))
(setq racers '('("pilot1" 0) '("pilot2" 0) '("pilot3" 0) '("pilot4" 0) '("pilot5" 0)))
(for i 0 4
(block (testPilot)
(setq testPilot (random pilots))
(lnkRemove pilots testPilot)
(lnkReplace racers i testPilot)
)
)
Post Reply