Script Engine Changes

The place to discuss scripting and game modifications for X³: Farnham's Legacy

Moderators: Moderators for English X Forum, Scripting / Modding Moderators, Moderators for the X3:FL Forums

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Script Engine Changes

Post by Cycrow » Fri, 9. Apr 21, 15:53

There have been large number of changes to the Script Engine and Editor.

The Editor itself has had some improvements to hopefully make it a bit easier and quicker to work with.
  • More Categeories and sub menus have been added for the commands to make it easier to find the commands you need
  • Some of the commands have been move to different menus where it makes sense
  • The Search Filter can be used to filter the list of available commands so you can just type in what you are looking for
  • An 'All Commands' section has been added that shows all the commands in a single list, useful when using the search filter
  • The parameter/variable menu has tabs added and split up the various selection so you dont need to scroll alot to find things
  • The parameter/variable menu also works with the search filter to quickly find things
  • The Search filter also works in the script listing, and the various selection menus.
A in depth explanation to the changes and additions can be found in the Script Engine page on confluence. There is also a list of script commands and list of script constants, both way too long to fit in a forum post.

For questions and discussion reply to this topic.
Last edited by Cycrow on Fri, 9. Apr 21, 16:44, edited 1 time in total.

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Wed, 26. May 21, 17:50

I played a little with the new engine and modernized the Ship Browser.
How wonderful the menus are. Great job guys.

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Sun, 14. Nov 21, 11:51

The game has a script command

Code: Select all

$Ware = get ware from subtype name 'String'
Is there a command opposite to this? Something like

Code: Select all

$SubtypeName = get subtype name from: type = 0 subtype = 0

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Tue, 16. Nov 21, 08:08

On the ship, I set the number of additional goods Fighter Drone = 6 pcs.
The script command 'get resupply table' shows 7 pieces, and the script command 'get additional resupply: ware' shows 6 pieces. Why is that?

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24950
Joined: Sun, 2. Apr 06, 16:38
x4

Re: Script Engine Changes

Post by X2-Illuminatus » Tue, 16. Nov 21, 20:41

Deniskos wrote:
Sun, 14. Nov 21, 11:51
The game has a script command

Code: Select all

$Ware = get ware from subtype name 'String'
Is there a command opposite to this? Something like

Code: Select all

$SubtypeName = get subtype name from: type = 0 subtype = 0
With subtype name you mean SG_xxx_yyy? If so, <RetVar> = get galaxy subtype: type=<ware> or <RetVar> = <RefObj> get galaxy subtype should do the trick.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Wed, 17. Nov 21, 03:27

Does this 'get ware from subtype name' script command use the galaxy subtype? Of course not, I meant the subtype name from TWareT, TShips, etc :wink:

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24950
Joined: Sun, 2. Apr 06, 16:38
x4

Re: Script Engine Changes

Post by X2-Illuminatus » Wed, 17. Nov 21, 19:37

I'm afraid, I feel like we're talking past each other. :gruebel: The galaxy subtype is what's stored in the types files (TShips, TWareT etc.) and you get it with the command I mentioned.

If you have the maintype and subtype id, you get the ware from one of the types files with the command <RetVar> = get ware from maintype <Var/Number> and subtype <Var/Number>. You can turn it into a string using <RetVar> = sprintf: fmt = <Var/String>, <Value>, <Value>, <Value>, <Value>, <Value>.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Thu, 18. Nov 21, 03:52

I'm afraid you don't read carefully)), or you don't know how the script command works.

Code: Select all

$Ware = get ware from subtype name 'SS_SH_A_TL' 
It returns the item from the subtype name, or subtype id. And it would not be bad to have an opposite command to get its subtype name or subtype id from the product. It could be used to create a string of arguments for '[MEvent.Switch]' in 'add value selection to menu:'
Here is a small piece of code using it:

Code: Select all

.
.
$Serialise = $Station-> serialise object
$WareM = get maintype of ware $Ware
$WareS = get subtype of ware $Ware
$SubtypeName = get subtype name from: type=$WareM subtype=$WareS
$Return = sprintf: fmt='%s|%s|%s', 'can.buy', $Serialise, $SubtypeName, null, null
add value selection to menu: $Menu, text=$Text, value array=$Values.YesNo, default=$Default, return id=$Return, width=null allowtabs=[TRUE]
.
.

Code: Select all

.
.
else if $AState == [MEvent.Switch]
   $MenuID = $AValue [0]
   $SelectedID = $AValue [1]
   $Value = $AValue [2]
   if $MenuID == 'FDN.Ware.Menu'
      $SelectedArray = split string: $SelectedID separator='|'
      $Command = $SelectedArray [0]
      if $Command == 'can.buy'
	 $Serialised = $SelectedArray [1]
	 $Station = convert serialised string to object: string=$Serialised
	 $SubtypeName = $SelectedArray [2]
	 $Ware = get ware from subtype name $SubtypeName
	 $Pointer = sprintf: pageid=$PageID textid=4000, $Ware, null, null, null, null
	 $WareSettings = $Station-> get local variable: name=$Pointer
	 $WareSettings [3] = $Value
      end
.
.
And this is only a small part of its application :wink:

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Script Engine Changes

Post by Cycrow » Thu, 18. Nov 21, 10:23

Such a command would be difficult to add, as it currently doesn't exist in the engine or KC. So updating the compiler to support it would be needed, which isn't really an option.

You could just pass the main and subtype of the ware then join them back together again to get the ware.

If you prefer a single value, you could convert the ware type to an int. Then convert the string to an int, and convert the datatype of the int to a ware

Code: Select all

$ware = change datatype [ $ware ] = DATATYPE_INT

Code: Select all

$ware = $strings[1]
$ware = string $ware to integer
$ware = change datatype [ $ware ] = DATATYPE_WARE
another option would be to create the lookup table yourself
read the various T files and extract the name ids, then put these into a table. Then when ever you need to get the ware type, use the table to do the lookup

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Thu, 18. Nov 21, 11:49

Cycrow wrote:
Thu, 18. Nov 21, 10:23
If you prefer a single value, you could convert the ware type to an int. Then convert the string to an int, and convert the datatype of the int to a ware
This option is also suitable, thanks.
For me, there are always few opportunities available in the game :)
Cycrow wrote:
Thu, 18. Nov 21, 10:23
another option would be to create the lookup table yourself
read the various T files and extract the name ids, then put these into a table. Then when ever you need to get the ware type, use the table to do the lookup
It will be a waste of system resources.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Script Engine Changes

Post by Cycrow » Sat, 27. Nov 21, 16:13

so apparently, i did add a command to get the name that i completely forgot about

Code: Select all

$name = get type name from type code: type=$ware

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Thu, 2. Dec 21, 03:24

Thanks, this will help a lot.
I am engaged in remastering these plugins:
Freight Distribution Network, Strategic Sector Defence Network

Here you can see how they work.

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Tue, 7. Dec 21, 07:43

What does this script command do and how do I use it?

Code: Select all

%0get abbreviation text: type=%1, key=%2

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Script Engine Changes

Post by Cycrow » Tue, 7. Dec 21, 09:54

It returns the text of a given abbreviation.
These are the ones displayed in the encyclopedia.

They are stored in tables with a key to identify them. For most, the key is just the English string, for others it's the objecy/type

You can also add your own too.

I belive there are constants available for the types

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Fri, 10. Dec 21, 16:47

As far as I understand, before you extract something using

Code: Select all

$Ret = get abbreviation text: type = 0, key = $Value
$Ret = get abbreviation description: type = 0, key = $Value
need to add something with

Code: Select all

add encyclopedia abbreviation: type = 0, key = $Value, value page = 0, value id = 0, data page = 0, data id = 0
For script command

Code: Select all

$Object -> attach event script: events = 0, script = 'ScriptName'
there is really not enough event like [Event.SetHomebase]))

But what this script command is for, I didn't understand something at first glance

Code: Select all

add script event: name = 'String', script = 'ScriptName'
What is it for?

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Script Engine Changes

Post by Cycrow » Fri, 10. Dec 21, 17:41

Deniskos wrote:
Fri, 10. Dec 21, 16:47
As far as I understand, before you extract something using

Code: Select all

$Ret = get abbreviation text: type = 0, key = $Value
$Ret = get abbreviation description: type = 0, key = $Value
need to add something with

Code: Select all

add encyclopedia abbreviation: type = 0, key = $Value, value page = 0, value id = 0, data page = 0, data id = 0
You can also get some of the existing abbreviations as well, as they are added in the same way, you just need to know the key's for them
Deniskos wrote:
Fri, 10. Dec 21, 16:47
For script command

Code: Select all

$Object -> attach event script: events = 0, script = 'ScriptName'
there is really not enough event like [Event.SetHomebase]))
The events are just the existing internal events that are used for things, so it only made these events available via scripts too. the MD uses the same events for some of its cue's as well
Deniskos wrote:
Fri, 10. Dec 21, 16:47
But what this script command is for, I didn't understand something at first glance

Code: Select all

add script event: name = 'String', script = 'ScriptName'
What is it for?
This allows you to create a new event that you can watch for via other scripts and the MD
There is a script command that can trigger these events

the name is the way to identify each event, and you can attach multiple scripts to the same event. So for example, you could trigger some event somewhere, and have any number of scripts that listen for that and do something. This can allow better collaboration between different mods and the MD

its actually used by the explorers guild script to trigger the Terran Plot from the comm script

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Fri, 10. Dec 21, 18:21

In general, events in SE are a big plus in the performance of the game engine. Rather than creating loops to track events, it is better to use calls or signals in the desired events.
Where were you guys before, respect to you!

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Tue, 21. Dec 21, 11:42

How do I get the return value in a script command?

Code: Select all

<RetVar> <RefObj> -> open menu script: <scriptname>
It always returns null for me.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Script Engine Changes

Post by Cycrow » Tue, 21. Dec 21, 12:01

There is more information here
https://www.egosoft.com:8444/confluence ... =102368099

but you return an array from the "arguments" event, and this becomes the return value

Deniskos
Posts: 146
Joined: Wed, 11. Jun 08, 21:40
x4

Re: Script Engine Changes

Post by Deniskos » Sun, 23. Jan 22, 12:11

What does this script command do?

Code: Select all

<RefObj> get docking port class string: flags=<Var/Number>
Spoiler
Show
Image
Maybe it should look like this -

Code: Select all

<RefVar> get docking port class string: flags=<Var/Number>
Also I can't figure out what this script command does?

Code: Select all

<RetVar/If><RefObj> get ship in docking port: port=<Var/Number>
It always returns null for me.

Post Reply

Return to “X³: Farnham's Legacy - Scripts and Modding”