AI Scripting/Modding questions

This forum is the ideal place for all discussion relating to X4. You will also find additional information from developers here.

Moderator: Moderators for English X Forum

Mad_Joker
Posts: 274
Joined: Sun, 14. May 06, 11:21
x3

AI Scripting/Modding questions

Post by Mad_Joker » Tue, 12. Sep 17, 08:14

Hi,

it's been some time since I modded X:Rebirth but now I am getting excited again about being able to mod X4 (although it seems to be still far off based on all the "I don't know yet" answers in the FAQ).

From all the info I gathered it seems that scripting will not change very much between X:R and X4, i.e. we still have the XML based MD and the XML based AI scripts. While there is some documentation on the internet regarding the MD there is almost nothing I could find regarding AI scripts. I just had a look at my old scripts for UFO and remembered the kind of workarounds I had to do to get some basic functionality. My biggest gripe back then was having no easy way to create a Map/Hash/Dictionary (or maybe I just never found it).

I'll use this thread to ask all those questions that I should have asked back then and figure out if I can make the scripts easier. So here's the first basic one: How can I create the equivalent code for the JavaScript snippet below in XML AI script?

Code: Select all

var hash = {
  a: 2,
  b: {
    c: 'string'
  },
};
Back in the day only actors had a 'blackboard' that could be used to store variables. Therefore I had to create a virtual actor for every hash I wanted to create. Please tell me there's an easier way.

PS: I am thinking about writing a JavaScript/TypeScript to MD XML transpiler to be able to code a bit easier. Therefore most of my questions will be targeted at translating JavaScript snippets to MD XML.

lostProfitssssArrgh
Posts: 161
Joined: Tue, 22. Aug 17, 13:14

Post by lostProfitssssArrgh » Tue, 12. Sep 17, 09:27

Hello,

Nested arrays..? I don't know much about xR scripts, but i'll try my luck :

https://stackoverflow.com/questions/257 ... ndroid-xml

https://www.w3.org/2005/07/xml-schema-p ... g-Elements

http://www.blackwasp.co.uk/XMLArrays_1.aspx

Now, whether xR supports those... idk :(

Hope this helps,
-lpa

Xenon_Slayer
EGOSOFT
EGOSOFT
Posts: 13097
Joined: Sat, 9. Nov 02, 11:45
x4

Post by Xenon_Slayer » Tue, 12. Sep 17, 10:45

We did add tables in one of the patches. I've just noticed that the MD pdf hasn't been updated in a while, so it's not mentioned there. Here's a rundown from our internal documentation (I'll see if we can update the pdf at some point).
Tables are associative arrays - they are like lists, but you can assign values to (almost) arbitrary keys, not just to index numbers. A table is constructed within an expression using the table[] syntax. See the section about value properties for how to access the contents of a table. Creating and removing entries works similarly to lists, but instead of inserting, you simply assign a value to a table key. If the key does not exist yet, it will be created.

Almost all values are allowed as table keys, but there are a few exceptions:

Strings must start with '$', like variables
null cannot be used as table key (but the number 0 is valid)
Lists, tables, groups and buildplans cannot be used as table keys

These restrictions only apply to the keys, there are no restrictions for values that you assign to them. For example:

table[] ⟹ creates an empty table
table[{0} = null] ⟹ creates a table that maps the number 0 to null
table[{'$foo'} = 'bar'] ⟹ a table that maps the string '$foo' to the string 'bar'
table[$foo = 'bar'] ⟹ exactly the same, just a shorter notation for string keys
table[foo = 'bar'] ⟹ error, 'foo' does not start with a '$'
table[{1} = [], {2} = table[]] ⟹ a table that maps 1 to an empty list and 2 to an empty table
<set_value name="$mytable.{$ship}" exact="$ship.speed"/> ⟹ Use the set_value action to map object $ship to its current speed value

Just like lists, tables are stored as references, so it's possible that multiple variables reference the same table.
Just as you could have had nested lists, you can have nested tables. Just depends on what you want.

Edit: You should actually be able to view the up to date documentation here.

Mad_Joker
Posts: 274
Joined: Sun, 14. May 06, 11:21
x3

Post by Mad_Joker » Tue, 12. Sep 17, 21:54

Oh my god yes, this is exactly what I needed. Let's see if I can get a transpiler working.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Post by Morkonan » Tue, 12. Sep 17, 22:37

Just a non-codemonkey comment: Stuff like this sort of interaction is critical, IMO. Mods have a very intimate connection with X releases and fans. Eventually, just about everyone mods their game. (Not all, but enough.)

So, continuing the support that Egosoft has traditionally shown for their modders and, at times, even contributors, is something a healthy X game dev cycle has to include.

PS - I know nothing of practical use in creating mods for X games. I'm a 3D modeler-hobbyist, though. Any tips where I can go to see what conventions/standards the new X game may use in that regard? Is it "just like" XR and, if so, are there some clear guidelines for modeling on that? (Wouldn't mind getting started, in advance. :) )

User avatar
MegaJohnny
Posts: 2202
Joined: Wed, 4. Jun 08, 22:30
x4

Post by MegaJohnny » Tue, 12. Sep 17, 22:43

I still remember your associative array library that used stations and NPCs! Those were the days.

It's really nice to see you posting again.

Return to “X4: Foundations”