Deep scripting questions

Freeform discussion about anything related to modding Transcendence.
Post Reply
The Wicked Flea
Miner
Miner
Posts: 25
Joined: Tue Jul 24, 2007 8:24 pm

Hey George, and anyone else who learned what I am asking through experimentation, I have a few serious questions on the scripting engine for you.

Firstly, are global sections (<globals></globals>) permitted/supported in mods? I am looking to store a table of modifiers outside a station or the player object; I would prefer to avoid hacks to do so. ;)

Secondly, what are the primary functions for lists/tables? I am aware of the usage of most functions like setq, lambda, list, random, rollDice and such ... but not for actual support of grabbing data from tables. I have read the reference for most the system functions too. I think I get the basic use of enumwhile but I'm uncertain (I'm drawing from the Teraton source file to study that).

Thirdly, are the variables listed in blocks local variables within that block? So far I feel that is accurate.

Finally, are standard [Common] Lisp functions such as with or do implemented?
Burzmali
Militia Commander
Militia Commander
Posts: 395
Joined: Tue Aug 15, 2006 12:14 am

Search for topics about arrays and lists, I have asked several similar questions in the past ;)
The Wicked Flea
Miner
Miner
Posts: 25
Joined: Tue Jul 24, 2007 8:24 pm

Thanks. I still need answers to the first, third, and last questions answered though. Although I meant "when" not "with". :D

The only threads I uncovered that I had not read and were relevant were this thread, and this one as well.

Lisp is a very interesting language I must say. Even this homebrew variant is interesting. It's actually easier for me to learn when compared against Lua, and I like the latter too. Though I wonder if George knew/knows about the implementation called ECL.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

The Wicked Flea wrote:Firstly, are global sections (<globals></globals>) permitted/supported in mods? I am looking to store a table of modifiers outside a station or the player object; I would prefer to avoid hacks to do so. ;)
Yes, <Globals> inside of modules are fully supported and will be in the future.

Also remember that you can use global data structures inside of StationTypes and ShipClasses to store static data (e.g., missions)
The Wicked Flea wrote:Secondly, what are the primary functions for lists/tables? I am aware of the usage of most functions like setq, lambda, list, random, rollDice and such ... but not for actual support of grabbing data from tables. I have read the reference for most the system functions too. I think I get the basic use of enumwhile but I'm uncertain (I'm drawing from the Teraton source file to study that).
Use (item [someList] [index]) to grab any element of a list. For example, in the list:

(setq theList '("A" "B" "C"))

(item theList 0) -> "A"
(count theList) -> 3
The Wicked Flea wrote:Thirdly, are the variables listed in blocks local variables within that block? So far I feel that is accurate.
Yes, that is correct.
The Wicked Flea wrote:Finally, are standard [Common] Lisp functions such as with or do implemented?
No, unfortunately not.

Use:

(enum theList someVar expression)
(enumwhile theList condition someVar expression)
(for someVar start stop expression)
The Wicked Flea
Miner
Miner
Posts: 25
Joined: Tue Jul 24, 2007 8:24 pm

Thanks for the answers George. So would something like this work?

Code: Select all

    ;; I modded the when function in.  Basically if the first argument evals true,
    ;; just call the expressions passed.
    (setq when (lambda (expression doThis)
      (if (expression) (doThis) Nil)))

    (when (true) (objSendMessage gPlayerShip Nil "When will we get there?"))
Can I pass functions as variables to a function? If so I could script in some more advanced list handling things like remove-if-not.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

I'm not near the source code, so I can't check right now.

Remember that function arguments are evaluated before they are passed in, so in your example the (objSendMessage...) call would be evaluated and the result of the call is passed in to (when...).

You could call it like this:

Code: Select all

(when true '(objSendMessage...))
Notice the ' in front. But this is inconvenient. What you really want is to define the (when...) function so that it does not evaluate its arguments.

You might try this:

Code: Select all

(setq when (lambda (expression &doThis)
   (if expression (eval doThis))
))
Notice the & in front of doThis. I'm not sure about it, but I think that's the right character.

Also, notice that I don't add parentheses around 'expression'. Parens in Lisp are used to denote function calls.

One question: It seems like your definition of 'when' is just a subset of 'if'. Why not just use 'if'? Of course, if you prefer 'when' syntactically, that's OK too.
The Wicked Flea
Miner
Miner
Posts: 25
Joined: Tue Jul 24, 2007 8:24 pm

Conciseness and understandability of course. It serves the same purpose in Lisp as dotimes and dolist when compared against do. The latter has very complex syntax but great functionality, while the others are slightly limited but more understandable. This way if I want to do something that is only evaluated when the if is true I can use when. A matter of programming convenience and all. ;)

But also to learn your variant of Lisp. When, in Common Lisp, is a macro that is exactly what I defined, only it is a macro instead of a function. So the more I try and experiment with the more I understand. Unlike you, I don't ever get access to the source. :P
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

OK, I take it back--I'm completely wrong:

Turns out that I haven't implemented a way to pass un-evaluated arguments into a user-defined function. The & syntax won't work for you, unfortunately.

I will, however, add it to the next version of the game.

Sorry about that!
The Wicked Flea
Miner
Miner
Posts: 25
Joined: Tue Jul 24, 2007 8:24 pm

No problem at all. Passing it quoted and calling the variable as a function causes the expression to be evaluated. At least in theory; I'll test that shortly.

With the ability to pass an unparsed parameter I can script in things like remove-if-not which will let me do some more advanced scripting things.
Post Reply