Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Thanks, but this does not work. api.engine is defined when load() is first called in either thread, and api.gui is not.
DEVS: If this is how you intend mod initialization to work, please document it.
Ah, I see. Now I got it. Then yes, this doesn't work.
These gamescripts are rather confusing at times with their threads and what runs where and whatnot.
https://github.com/Vacuum-Tube/Advanced_Statistics_1/blob/main/res/scripts/advanced_statistics/thread.lua
However, in the init process, keep in mind, it's more difficult because not all things exist from the start. For example, if the game script files are read in the first time, api is only {}.
The gamescript is indeed confusing, because the same file will create 2 instances in the game in different threads (engine+gui). However, the load function is the only one that is called in both. I have already written about this and other issues to UG.
https://www.transportfever.net/index.php?thread/16887-game-script-save-function-unerkl%C3%A4rliches-verhalten/&postID=342719&highlight=gamescript#post342719
Thanks for your response.
Is your getCurrentThread() function any more complex than I suggested above, ie checking if game.interface.sendScriptEvent is not nil ?
In my experiments I found that the save method is also called in the GUI thread one time, after the engine load() and initial GUI load(). If the GUI save() call returns a different state than was load()'ed, there is an assertion failure due to the gui and engine state being different. However, I think the GUI thread save() is not called after this check is done.
The function can check other game threads, too.
Excactly, the init behavior is a bit confusing. I also wrote that in the linked forum post.
My results:
The same is done for gui thread. For whatever reason save is called 2x in script thread.
I don't know why the Assertion for being the same Save result exists, but it really came in my way. Because I wanted to load only parts of state (settings), the rest was not important to recover because it is recalculated. The rest also included a init flag which should NOT be recovered with init=true from the savegame.
Meanwhile, in the load the new state needs to be saved but maybe also other things. This is done 5x per second.
So the load function does basically 2 different tasks.
Hi, and thanks for your response.
The need to persist only part of the state is probably quite common among mods. It sounds like you only persist settings, but some mods might need to persist other state which cannot be re-generated. I ran into this issue also. Here's how I solved it:
I noticed that the serializing process follows these steps:
Using this observed behaviour; my code does the following:
I'm hoping to release two mods I'm working on soonish, which use this technique.
I'm trying to initialize my new script mod correctly during the first load() call, but with @VacuumTube's help, I think I have it figured out. Thank you for your feedback!