[X3:LU] Question about global variables and startup scripts.

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

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

Post Reply
User avatar
Zaitsev
Posts: 2005
Joined: Tue, 2. Dec 08, 01:00
x4

[X3:LU] Question about global variables and startup scripts.

Post by Zaitsev » Sun, 25. Jul 21, 23:44

So, I've worked out most of the kinks in my maintenance cost script, but a couple of questions have popped up.

1 - Are global variables permanent? As in can I set them once and they will forever be accessible, even after a reboot of the game, or do they have to be loaded every time I start the game?

2 - I want my script to start automatically when I start the game, so I don't have to run it manually every time. How do I make this happen? I've been digging through various posts and other scripts, but couldn't find a definitive answer.

Edit: So, after some more digging, and a bit of experimentation, it looks like having a script called startup.somethingdescriptive.xml that initiate the necessary scripts will get the job done. That all but solves my second question, but since I'm still green as grass when it comes to scripting I'm wondering if there are any drawbacks to this method. Is there a chance it will bork at some point, or can it be regarded as "good enough" for what is basically a non-essential task? I mean, if the worst thing that happens is that it takes a few extra seconds, or even minutes, to get going, that's just fine. If the worst thing that can reasonably happen is that the script fails to do its job, that's a bigger problem.
I'm sorry, I can't hear you over the sound of how awesome I am :D

DiDs:
Eye of the storm Completed
Eye of the storm - book 2 Inactive
Black Sun - Completed
Endgame - Completed

User avatar
Hector0x
Posts: 994
Joined: Mon, 18. Nov 13, 18:03
x3tc

Re: [X3:LU] Question about global variables and startup scripts.

Post by Hector0x » Tue, 27. Jul 21, 15:40

1) Global variables get saved in your savegame
2) from MSCI Handbook:
Spoiler
Show
Script names beginning with “init.”, “setup.”, “al.plugin.”, and “galaxy.” all have special
meanings as well. They are all run automatically by the game at certain times.
• Init Scripts: Scripts with names beginning with “init.” or “!init.” are run automatically
every time a new game is started or loaded. They can be used to configure menu
commands, and at one time were used extensively to do just that. However, they are run
very early in the process of starting or loading a game, at a time when many aspects of the
galaxy aren't initialized yet. Before the galaxy's stations and ships have been created.
Because of this, special precautions have to be taken in an init script if it is do do something
like, for example, adding a new upgrade to an equipment dock. Because of these
limitations, the use of init scripts has largely been discontinued in favour of:
• Setup Scripts: Scripts with names beginning with “setup.” or “!setup” are also run
automatically every time a new game is started or loaded. These scripts, however, are run
later on in the game initialization sequence. All the galaxy's stations and ships will have
been created before the setup scripts are run. This makes them much safer and easier to use
as a general configuration system than init scripts.
i'd say you need a setup script which calls the script that controls the timer at which money is taken from your account. This timer script runs in an indefinite loop and the exact playtime of the next payday gets stored as global variable in your savegame.

User avatar
Zaitsev
Posts: 2005
Joined: Tue, 2. Dec 08, 01:00
x4

Re: [X3:LU] Question about global variables and startup scripts.

Post by Zaitsev » Wed, 28. Jul 21, 23:49

Hector0x wrote:
Tue, 27. Jul 21, 15:40
1) Global variables get saved in your savegame
2) from MSCI Handbook:
Spoiler
Show
Script names beginning with “init.”, “setup.”, “al.plugin.”, and “galaxy.” all have special
meanings as well. They are all run automatically by the game at certain times.
• Init Scripts: Scripts with names beginning with “init.” or “!init.” are run automatically
every time a new game is started or loaded. They can be used to configure menu
commands, and at one time were used extensively to do just that. However, they are run
very early in the process of starting or loading a game, at a time when many aspects of the
galaxy aren't initialized yet. Before the galaxy's stations and ships have been created.
Because of this, special precautions have to be taken in an init script if it is do do something
like, for example, adding a new upgrade to an equipment dock. Because of these
limitations, the use of init scripts has largely been discontinued in favour of:
• Setup Scripts: Scripts with names beginning with “setup.” or “!setup” are also run
automatically every time a new game is started or loaded. These scripts, however, are run
later on in the game initialization sequence. All the galaxy's stations and ships will have
been created before the setup scripts are run. This makes them much safer and easier to use
as a general configuration system than init scripts.
i'd say you need a setup script which calls the script that controls the timer at which money is taken from your account. This timer script runs in an indefinite loop and the exact playtime of the next payday gets stored as global variable in your savegame.
You're a savior, Hector0x. This was very helpful, and along with finding the X2 MSCI handbook I've been able to make some good progress. Thank you for your help!
I'm sorry, I can't hear you over the sound of how awesome I am :D

DiDs:
Eye of the storm Completed
Eye of the storm - book 2 Inactive
Black Sun - Completed
Endgame - Completed

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”