information about coderarray/scripts

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

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

User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

information about coderarray/scripts

Post by Moonraven »

Hi,

well..i played around with the coderarray of a script, because the internal editor ist no real good for large scripts.

Ok..here are the results of the experiments:

All entrys are sval-entrys with attributes val and type.

The meaning of the entry depends on the level of the entry.


Level 0:

Entry 0: Root entry; allways has the val 10 and the type array.

Level 1:

Entry 1: Val is the name of the script type is string
Entry 2: Val is allways 25 type is allway int (unknown meaning)
Entry 3: Val is allways "Description" type is allway string
Entry 4+5 val alway 0 type allway int (seems to be deviding to the
real codebased part of the codearray)

Entry 6: Another array; size depends on the number of variables used
in the script. type is array

Every subentry contains the name of a variable as type
string; for example if you use a variable called i in the script
in this part, there is a entry with val "i" and type string.

Entry 7: The script code itself. explained later here.
Entry 8-10: allways val 0 type int; seems to be a mark for end of
the script.

ok...know to the script-part (entry 7):

The first level is always a array definition, depending on how many lines the script will have. For example, if you have a script with 4 lines, this entry will have val 4 type array. For the next level there is the next array definition (for each line of the script one array). size depends on how much parameters the command of the line will have. For example, if you have a line with an INC-Statement, you have val 2 type array.

The next level, descripes the commannd of a line, with its parametes.

The first sval-entry is the command itself. val seems to be the number of the corresponing entry at page 2003 in the languagefile. For example if you have an INC statement there is the val 142 with type int.

The next entrys are the parameters of the script. For variables, this is the number of entry in the array for variablenames above (based on zero).

So fare my knowlage about the codearray. Seems to be very simple :)


Hope this helps to get a external editor sometimes :)
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]
User avatar
Serial Kicked
Posts: 3823
Joined: Fri, 12. Aug 05, 20:46
x3tc

Post by Serial Kicked »

OMG THANKS !!!

Even at 8'oclock in the morning without any sleep I understand this explanation. With the <codearray> issue solved i don't see any problem left in the making of an external editor.

Yeeepeee !

I've some other little things to do before starting this project, but i'm quite sure i'll begin to write this program soon.


Btw, huuuum, without breaking any NDA rule, is it possible for those who know the secrets of X³ to tell us if the method used to produce scripts xml will change ? I don't really want to code something that will be completly outdated when X³ will be available.
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System

Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
laprican
Posts: 196
Joined: Fri, 13. Feb 04, 16:56
x2

Post by laprican »

Ok... some additions and corrections

Entry 2: Version of the scriptengine
Entry 4: Version of the Script
Entry 5: First I thougth its always zero, too. But than I found a script, thats value here was 1 but i couldn't find something special about it...

Entry 8: Array containining the Arguments of the script, if its emtpy ist int(0)
There are size subelements of array(size).
The subelements contain two elements:
int(argumenttype)
string(decription)
The varname of a subelement is the one in the vars section at the same position.

Entry 9: Scriptcommands not needed by the scriptinterpreter, such as end, else or comments. Type is array(size) or int(0) if empty
Has size subelement of type array(size)
First is int(line to insert) and the rest is the same as of
Entry 10: Is string(value) or int(value). This is the command description displayed when the script is executed on a ship.
User avatar
Serial Kicked
Posts: 3823
Joined: Fri, 12. Aug 05, 20:46
x3tc

Post by Serial Kicked »

This is exactly what i like with this board, ask for something that looks impossible (as decrypting a wild array of integers) and you got clear and detailed answers. I don't have time now to check both but i'll definitively give a look at this after the weekend.

Thanks to both :)
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System

Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

Post by Moonraven »

@labrican

Thanks for the additional informations. i translated it to german in the german forum :)

@SerialKicked

It may not be that easy, as you think, because you have to do a lot of work with the parameters of the statements and the corresponding numbers for the codearray :)

If you make a editor, wich programinglanguage do you use ?
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]
User avatar
Birdman
Posts: 508
Joined: Sat, 10. Jan 04, 09:07
x3

Post by Birdman »

SerialKicked wrote:OMG THANKS !!!


Btw, huuuum, without breaking any NDA rule, is it possible for those who know the secrets of X³ to tell us if the method used to produce scripts xml will change ? I don't really want to code something that will be completly outdated when X³ will be available.
Posted on here: script in KC programming language.

http://lbasic.atomysk.com/trucs/kcprogramming/index.htm (French)

http://www.libertybasic.com/ (English)

Looks like a combination of C and Basic to me. :)
User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

Post by Moonraven »

@Birdman

The intention is not do write a editor for KC, because KC needs to be compiled (real compiled like C) and then has to be included in the game-executable.

The intention is to write a editor (external) for the script-language of X2. Currently there is only a game-internal editor for this. :)
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]
User avatar
Birdman
Posts: 508
Joined: Sat, 10. Jan 04, 09:07
x3

Post by Birdman »

@Moonraven

OK, I thought this was about scripting for X3. From what I had read, it sounded like KC would be needed for X3 scripting.

Sorry I misunderstood. :oops:
User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

Post by Moonraven »

No Problem. :)

But..about X3...KC would be the scriptlanguage.

I heard this also. Some people say this, other say, that the current scriptlanguage would be the same as in x2 with some extends.

Well....we will see :)
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]
User avatar
Birdman
Posts: 508
Joined: Sat, 10. Jan 04, 09:07
x3

Post by Birdman »

Heard the same thing :) , be interesting to find what other goodies they add.
User avatar
Serial Kicked
Posts: 3823
Joined: Fri, 12. Aug 05, 20:46
x3tc

Post by Serial Kicked »

@Moonraven : Yup i know it's not easy. There's also a ton of parsing routines to make in order to load all the data from the xml / language files. If i make it, it'll be designed in Delphi. I'm still not sure, but i'll probably release the source code.


@Birdman : About KC and X³, it's something wrong i said before. X³ script system won't be in KC. This language is only used to write missions in the X games. Sorry.
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System

Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

Post by Moonraven »

@SerialKicked

Wow...another delphi-coder :) I also work with delphi. Maybe we can do the work together :)
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]
User avatar
Serial Kicked
Posts: 3823
Joined: Fri, 12. Aug 05, 20:46
x3tc

Post by Serial Kicked »

Nice to see there's not only C/C++ coders (no offense guys :) ) here. I'm not really used to co-working on projects, but this one is quite huge, so why not.

I've still some projects to finish first and some infos to gather on the differents formats and tricks used by X script engine. After this we could start a dedicated thread to the editor.

By the way, if you're using an instant messanger (msn,icq or aim i don't care) feel free to send it to me via PM :)
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System

Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
User avatar
RedEclipse
Posts: 1269
Joined: Sat, 11. Sep 04, 16:43
x4

Post by RedEclipse »

As I said to SerialKicked in the french scripting forum, I can't see the type of the return value in the code array. It sounds like it should be somewhere between val 5 or val 8->10 to me. :roll: Maybe even entry 0 on lvl 0 if you studied only "return null" scripts. (non Delphi coder here, sorry guys ;) )
laprican
Posts: 196
Joined: Fri, 13. Feb 04, 16:56
x2

Post by laprican »

scripts can have alot of return values.
so the type isn't saved in the script.

a simple scriptloader based on the codearray can be found here
Last edited by laprican on Sun, 28. Aug 05, 19:00, edited 1 time in total.
User avatar
Serial Kicked
Posts: 3823
Joined: Fri, 12. Aug 05, 20:46
x3tc

Post by Serial Kicked »

Ouch i've finished to translate all of this in the french board. Quite tired :)

Sorry if i'm wrong.

let's say we have a script like :

Code: Select all

10 Inc(X)
20 Return(x)
The entry 7 will be like :
Array [ Integer(langagefile(INC)) ; Integer(entry6(X)) ] ;
Array [ Integer(langagefile(RETURN)) ; Integer(entry6(X)) ] ;

And if i'm right, what happens for the Return(null) command ? Is it like:

Array [ Integer(langagefile(RETURN)) ] ;
or simply nothing ?

I've still not read your source, laprican, sorry, way too tired to decypher C/C++ algorithms right now :) but i've some difficulties with your explanations of the Entry 9. I understand perfectly that "comments" aren't needed by the interpreter and can be stored here, but about the "else" or the "end" commands ?

Can you be a bit more descriptive about this part please ? :)

Thanks.
Last edited by Serial Kicked on Sun, 28. Aug 05, 18:05, edited 1 time in total.
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System

Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
User avatar
LV
Sith Lord
Posts: 8255
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by LV »

SerialKicked wrote:

Btw, huuuum, without breaking any NDA rule, is it possible for those who know the secrets of X³ to tell us if the method used to produce scripts xml will change ? I don't really want to code something that will be completly outdated when X³ will be available.

Without breaking the NDA (mainly because i'm guessing) I dont think it will change but it could.

There's always a possibility that some id's may change if new/more objects are added to the basecode, If this was to happen then i'd expect that your currently defined ware of an AHEPT could possibly change to Readtext-1239-09889-bla bla bla or an argon discoverer would become a teladi vulture or satan himself "unknown object" and then cause serious CTD's if you were porting x2 code to x3 to run on setup, but like i said i'm completely guessing here ;)

If i was you i'd code it for x2 and hope that x3 will only require some slight changes, that way making one for x3 will be alot easyer, its what i would do
LV's TC Scripts
Readme's For All My Scripts


I felt a great disturbance in the forum, Like millions of voices cried out in terror, then were silenced

si tacuisses, philosophus mansisses
laprican
Posts: 196
Joined: Fri, 13. Feb 04, 16:56
x2

Post by laprican »

SerialKicked wrote: ...
Can you be a bit more descriptive about this part please ? :)
Ok I will try ;)

The scriptinterpreter doesn't need the end, because the range of the if command is saved inside the <RetVarIf> Parameter.
If the value of <RetVarIf> is positiv it's an index to the variablesarra, else <RetVarIf> consists out of four parts, each 4 bytes of 32 byte value.
The first bit is only for displaying. Its an index to ("if", "else if", ...).
The second bit is the line where to jump.
The third bit is always zero IIRC. May the second and the third bit are the line where to jump(I haven't tested yet)
The fourth bit is whether to jump or not.
I dont have the exact values. But I think its was
80 => don't jump(" =" or "START")
128 => jump if following expression is false("if", "else if", "while", "skip if not")
160 => jump if following expression is true.("skip if", "if not", "else if not", "while not")

And the else command isn't needed, because the scripteditor replaces it with "hidden goto <Line>". Where line would be a reference to the line after the next "end". Hidden goto is also inserted before "else if" and at the and of an while-instruction.
User avatar
RedEclipse
Posts: 1269
Joined: Sat, 11. Sep 04, 16:43
x4

Post by RedEclipse »

laprican wrote:scripts can have alot of return values.
so the type isn't saved in the script.

a simple scriptloader based on the codearray can be found here
Scripts can have a wider argument value, that's not the reason why they aren't in the codearray... ;)

When you code something like
$toto = callscript something with $var and $var2 and $var3
(sorry for the typos, I don't know the exact command yet : se noob inside)

$toto's type must be definated before the calling procedure, not in the moment of the script returns a value, because of economy of cpu cycle. It's damn too long to evaluate if things are made dynamicly. This can be premade by saying "calling this script return only nulls, this one only boolean bit, this other one only an int... make $toto a null, make $toto a boolean, make $toto an int.", which are 90% of the script, or saying "calling this script returns a null or an int. $toto can be a null or an int." is faster than "calling this script returns... * scaning the whole script * a null or an int. $toto can be a null or an int.

25 differents type (how many in fact ? 32 ?) make a 25 bit int where each bit is the symbol for a type, far less than an int afterall. That's how I would code it if I were in Egosoft's secrets. I strongly advice to look better @ value 5.

[edit] Anyway, I've made test with a few sample scripts :
- 1 with an argument of the type "all ware" which was 001 return argument
- 1 with an argument of the type "int" which was 001 return argument
- 1 with no argument which was 001 $argument = 1 002 return argument
- 1 with no argument which was 001 sargument = "a brasil string" 002 return $argument

...and it seems the #5 is always set to 0. I really was expecting precalculated type of returns to be there, i'm very surprised.
Last edited by RedEclipse on Sun, 28. Aug 05, 20:30, edited 1 time in total.
laprican
Posts: 196
Joined: Fri, 13. Feb 04, 16:56
x2

Post by laprican »

Hm...

But the type is returned with the value, so you dont have to evaluate the value to get the type. In all $vars are stored both, type and value.

It looks like value 5 has something to do with sector names. If a sector name itselfes apperears in the script value 5 is "2" independent from the return types. And if you change the value to 0 the script won't load correctly.
So it could be something like a loadingorder.

And yes it looks like sf.net is down.

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