[List] What you should NOT do using the script editor

The place to discuss scripting and game modifications for X³: Reunion.

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

User avatar
SymTec ltd.
Posts: 5285
Joined: Mon, 11. Apr 05, 21:11
x3tc

[List] What you should NOT do using the script editor

Post by SymTec ltd. »

Here's a little list of things you should NOT do using the script editor. I do not suggest really using this code, as this will most certainly not do your game and computer any good. New code posted in this thread will be copied to this first post.

Example 1:

Code: Select all

while [TRUE]
end
return null
What will happen: Infinite loop - your game will hang, you may not ba able to terminate your game.

Example 2:

Code: Select all

$i = 0
while $i < 5
 if $i == 2
  ...
  inc $i
  end
end
What will happen: Infinite loop - your game will hang, you may not ba able to terminate your game. One of the most frequent mistakes people make.

Example 3:

Code: Select all

[PLAYERSHIP]-> destruct: show no explosion=[TRUE]
What will happen: You will die. Inavoidably.

Example 4:

Code: Select all

[PLAYERSHIP]-> put into environment Argon Prime
What will happen: Weird things. There will be graphics errors, sound errors, and a crash in the end.

Example 5:
insert special characters like ">", " < " etc. in Script comments
What will happen: Game will crash when loading the script files.

Example 6:
not closing tags in the text files, writing errors, wrong commands
What will happen: Game will crash when loading the text files.

Example 7:

Code: Select all

skip if [TRUE]
 return null
(at the end of the script)
What will happen: Game will crash when executing the script

Example 8:

Code: Select all

if <expression> OR <expression> OR <expression> OR <expression> OR <expression> OR <expression> OR <expression> OR <expression>
What will happen: Too long "OR"-statements are said to cause problems with the program. crash?

Example 9:
referring directly to objects in the current game
What will happen: script files won't save correctly

Example 10:
referring directly to sectors in the current game
What will happen: mod users get into trouble. dunno what exactly...

Example 11:

Code: Select all

$i == random value from 0 to 5
$k = 2500 / $i
What will happen: $i could be 0. Even the script editor cannot divide by zero. Haven't tried yet what will happen, but most certainly, nothing good.


Example 12:

Code: Select all

@ wait 2000 ms
in a setup.-script
What will happen: setup scripts cannot handle waiting times. Your game will crash whenever you load it. You cannot change the script, because your game will crash whenever you load it. Your only chance is to open the script with an external text editor and change its name to a name that does not start with setup in the codearray, then change the file name to the same name.

Example 13:

Code: Select all

$s = read text: page $pageid id: 001
with too much text in that textfile
What will happen: clean shutdown of all systems. I tried this with a textfile only consisting of one entry, which was 132KB - it did not work. I shortened the entry, so that it was only about one monitor full of text (19", size 12). It loaded, and the game crashed when I tried posting it to my player logbook.

Example 14:

Code: Select all

Argon Mammoth -> put into environment: Your Ore Mine(Ore Belt)
with of course variables for the objects
What will happen: ever tried hiding an elephant inside your wardrobe? dunno...
Last edited by SymTec ltd. on Wed, 28. Feb 07, 22:59, edited 1 time in total.
fud
Posts: 9837
Joined: Wed, 25. Jan 06, 14:26
x3

Re: [List] What you should NOT do using the script editor

Post by fud »

SymTec ltd. wrote:
Example 3:

Code: Select all

[PLAYERSHIP]-> destruct: show no explosion=[TRUE]
What will happen: You will die. Inavoidably.


:lol:

While painfully obvious, it begs the question: why would someone try that?
XGamer
Posts: 2355
Joined: Sun, 25. Apr 04, 19:09
x4

Post by XGamer »

You made some mistakes SymTec ;)

Example 2 wont cause a infinite loop at the current state. I get you ment the $i=0 after the while. Then it would be an infinte loop of course as $i will be set to 0 everytime the loop starts again and so it will be always 0 and therefore infinite (loop exits when $i is 5)

Example 5: im pretty sure i done so already - could load that files without problems (havent done that in 2.0.2 though)

Example 7: Script will never end. and always stay in memory. If its a script which is needed for another script i.e. for returning vars or calculating sth the script needing those information wont run properly and also get stuck as it waits for the called script do be done. (which will never be the case as it skips the return null every time.

Example 8: Not sure the game will crash but atleast the if structure wont work as expected.

Example 9 & 10: what do you mean with "refering directly to objects/sectors"?

Example 11: Well as you said division by 0 is not allowed. Possible Cases are: a) Egosoft programmed an error avoiding structure inside the SE and nothing bad will happen besides that the script wont work. b) Egosoft havent done such things and the game will crash due to an illegal operation.

greetz
XGamer
X:BtF: 7/10 | X2: 8/10 | X3:R/TC/AP: 8/10 | X:R: 3/10 | X4: 0/10 (3 points for split ships and stations, 4.0 -> -50 points).
If you are raising pirate activity, give me meaningful ways to deal with them PERMANENTLY. Better things to do than replacing ships every 10 minutes, or babysitting ships getting harassed.
Stopped playing X4 with 4.0 due to outrageous, needless and pointless nerfs to everything. Don't change what wasn't broken in the first place.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22432
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

XGamer wrote:Example 2 wont cause a infinite loop at the current state. I get you ment the $i=0 after the while. Then it would be an infinte loop of course as $i will be set to 0 everytime the loop starts again and so it will be always 0 and therefore infinite (loop exits when $i is 5)
i think you missed something there, if you look, the inc $i, is inside the if statement, so it will only inc when $i == 2, as it starts at 0, it will never equal 2, and will never increase the value, so its always 0, causing an infinite loop
XGamer wrote: Example 5: im pretty sure i done so already - could load that files without problems (havent done that in 2.0.2 though)
if u havn't had problems then im guessing u havn't done what hes suggestion, using the ">" and "<" in comments causes problems, because the scripts are xml parsed, the > and < characters are part of XML syntax, adding a comment causes it to write the string into the XML file which then makes it invalid, as the script editor doesn't convert these characters to something different.
XGamer wrote: Example 7: Script will never end. and always stay in memory. If its a script which is needed for another script i.e. for returning vars or calculating sth the script needing those information wont run properly and also get stuck as it waits for the called script do be done. (which will never be the case as it skips the return null every time.
im not sure if thats true or not, scripts should terminate when they reach the end, however, i say should, but there might be a problem with this that i havn't yet tested, i might try that.
XGamer wrote: Example 8: Not sure the game will crash but atleast the if structure wont work as expected.
true, i dont c this as a problem, i have made some pretty big if statements before without any problems, althou i do tend to put brackets around them, but that shouldn't realyl make any difference.
XGamer wrote: Example 9 & 10: what do you mean with "refering directly to objects/sectors"?
you basically cant directly reference any objects in a script, ie, if you have something like

Code: Select all

$sector = Argon Prime
it will work, but the script wont be saved to a file so when you clsoe the game, u lose it.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

example 7 will Freeze the Game like example 1 ;) i have tested it myself :D

I think, x3 wants to find the next existing line, which cannt be found in 100 Years because the Script Code has no more lines...
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
Ben2006
Posts: 145
Joined: Sun, 1. Oct 06, 01:19
x3

Post by Ben2006 »

Yes I have experienced "Example 5", but I did not understand why the SE did what it did ie: it erased all of the comment contained within the quotes. It was with this type of comment layout:

Audio: Play Speech: "The text within the quotes would dis. when reloading"

and show up like this in the SE after reloading the script:

Audio: Play Speech:


But, just using quotes in the comment like "this is a comment" seemed to be OK though.
User avatar
SymTec ltd.
Posts: 5285
Joined: Mon, 11. Apr 05, 21:11
x3tc

Post by SymTec ltd. »

@Cycrow: Example 10:

Code: Select all

$sector = Argon Prime 
Whatever you or anyone else says: I can save a script that contains this line, and I am able to open it again. My CrystalCorp Secrets-Script (Download) has got one file that consists to 30% of those statements. I was always able to save, reload, pack and send this to other people, and in their universe, the stations I create are in exactly the same place they are in mine.

Though, I haven't heard of anyone who plays a mod/new map-game with this yet...

@XGamer: Cycrow is right (exceptions possible) - in most cases, X³ does not react to those problems as you'd think it would do. You have to try, not guess. I experienced clean shutdowns where the game just finished (after I tried to load a "pretty long" string object), cases where it just crashed to desktop and could be restarted directly in the task bar, and (most often) crashes where I couldn't even terminate the program, so I had to break off the power supply of my PC - one of the most unhealthy things one can do to it.

@fud: I did it to check whether an option of my Emergency Jumpdrive script worked, where I connected the SIGNAL_KILLED to a script that would have saved my life, if not even my ship. It did not work.
XGamer
Posts: 2355
Joined: Sun, 25. Apr 04, 19:09
x4

Post by XGamer »

Ex.1 Oops™ yeah you're right Cycrow.. Missed that...

Ex.5 yep <> are part of most syntaxes ;) But he gave some more Characters which arent part of XML code afaik.

To Ex.8 I tried to use that kind of if structures (this OR this OR this) but they never worked as I wanted them to work sadly.

Ex.9/10 Why should you do such things? You could either make it as an argument or getting the sector otherwise if you dont want the user to set it.
X:BtF: 7/10 | X2: 8/10 | X3:R/TC/AP: 8/10 | X:R: 3/10 | X4: 0/10 (3 points for split ships and stations, 4.0 -> -50 points).
If you are raising pirate activity, give me meaningful ways to deal with them PERMANENTLY. Better things to do than replacing ships every 10 minutes, or babysitting ships getting harassed.
Stopped playing X4 with 4.0 due to outrageous, needless and pointless nerfs to everything. Don't change what wasn't broken in the first place.
User avatar
nirwin
Posts: 2879
Joined: Tue, 1. Nov 05, 23:07
x3tc

Post by nirwin »

Hi,

I hope this thread gets stickied as it is an absolutely fantastic idea.

Example 8, the overly long OR statement, yes it is a crash, but only on some computers. This crash was demonstrated in SectorTakeover v2.4

Another thing to note is that all the 'Get Notoriety' and 'get relation' commands that refer to races are bugged. They simply don't work. Someone please confirm, I will double check, but I am pretty certain.
The best work around I have found is to get the relation of one object to another, i.e. pick a ship of one race and a ship of another and see if they are friendly, it's not a perfect solution but works most of the time.

---EDIT---
And I will stop being lazy and post this up in code tonight, for the comfort of the OP
Nirwin
------
Sector Takeover | Unlimited Resources (x2/x3)
User avatar
al_main
Posts: 1379
Joined: Wed, 6. Oct 04, 10:26
x3

Post by al_main »

The get notoriety commands all work fine for me? :P

I reckon 14 will prob work fine btw, but you just probably wont be able to undock.
User avatar
nirwin
Posts: 2879
Joined: Tue, 1. Nov 05, 23:07
x3tc

Post by nirwin »

al_main wrote:The get notoriety commands all work fine for me? :P
Been a long time since I tried it, could have just been the relation commands, I will have a try in self contained scripts tonight and report back.
Nirwin
------
Sector Takeover | Unlimited Resources (x2/x3)
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22432
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

afaik, the get relation commands are not supposed to work between races, and are always the relation of the object to a race, which is y u could have had problems if you tryed to do it from race to race
User avatar
nirwin
Posts: 2879
Joined: Tue, 1. Nov 05, 23:07
x3tc

Post by nirwin »

Cycrow wrote:afaik, the get relation commands are not supposed to work between races, and are always the relation of the object to a race, which is y u could have had problems if you tryed to do it from race to race
I always use the commands as suggested, so I would have only used the races if they were indicated such as with <var/race>.

But anyway as I say I will see if I can come up with some concrete examples, if not forget I mentioned it. :)
Nirwin
------
Sector Takeover | Unlimited Resources (x2/x3)
User avatar
SymTec ltd.
Posts: 5285
Joined: Mon, 11. Apr 05, 21:11
x3tc

Post by SymTec ltd. »

Oh, I just found this in the [url=http://forum.egosoft.com/search.php][b]Se[/b]arch[b]Fu[/b]nction[/url] by accident again.

Are there any more problems to add to these? :roll:
User avatar
YBnorml
Posts: 123
Joined: Tue, 13. Jun 06, 01:30
x3

Post by YBnorml »

SymTec ltd. wrote:@Cycrow: Example 10:

Code: Select all

$sector = Argon Prime 
Whatever you or anyone else says: I can save a script that contains this line, and I am able to open it again. My CrystalCorp Secrets-Script (Download) has got one file that consists to 30% of those statements. I was always able to save, reload, pack and send this to other people, and in their universe, the stations I create are in exactly the same place they are in mine.
Sorry I'm abit confused here. I too have done this without any problems. Never lost anything. But I guess my next question would be is if were not really to do it this way, then how else do we define a single sector?

YB
Virtual is reality...
Y B Nor M/L
User avatar
SymTec ltd.
Posts: 5285
Joined: Mon, 11. Apr 05, 21:11
x3tc

Post by SymTec ltd. »

YBnorml wrote:Sorry I'm abit confused here. I too have done this without any problems. Never lost anything. But I guess my next question would be is if were not really to do it this way, then how else do we define a single sector?
First of all, there is no problem whatsoever in doing it like that. If there is, you can still always use the command

Code: Select all

$sector = get sector from universe index: x=$x , y=$y
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22432
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

the problem is when u hardcoded objects, sectors arn't too much of a problem, but other objects are.

but as SymTec said, you should really use the Get sector command instead, and if u use that, then u should also check if the sector exists.

this will insure that your scripts is compatable with mods that make changes to the galaxy.

you should avoid stuff like

Code: Select all

$ship = Your Argon Nova
if you try to access the ship or station directly, then will have problems saving

Return to “X³: Reunion - Scripts and Modding”