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
It might still be over my knowledge level right now, but is this the same idea as trying to reference things in cases where the "parent" may not exist?
For example I'll try code that retrieves info for a nearby station module, then I'll try to read or write into its metadata or something, and get index error messages because I didn't account for the fact that there may not actually be a nearby station module, or it may not actually have the data that I'm trying to access. So I've learned that I often have to do stuff like this:
if module and if module.metadata and if module.metadata.platform and if....
instead of just:
if module.metadata.platform.justgimmewhatIwant
Is it the same idea here, that you're trying to access .transportVehicleConfig or a [node] index without knowing that the parent actually exists or that it actually contains that data?
Thanks!
In the scenario I describe it would be something like this:
Note this problem does not apply to pure "lua" objects. If the "module" you started with was a pure lua table, then no problem.
I speculate that there is something in the way the TPF code sets up these objects (in C) has not considered the possibility of a strongly referenced child when the parent has gone out of scope.
As a newbie to this and without much coding background, tbh I've been completely confused at times by how data is handled within the TpF 2 modding ecosys. There's been times I've had my mind blown when I discovered I could reference something that I didn't think was available to me in the current context, and then times I've gone mad when it wouldn't let me ref something that I swear I should be able to (with seemingly random reasons why at times).
The docs are adamant there's no "globals" and yet a lot of things sure seem to act like globals to me, despite everything being defined local. Tbh now I just mash buttons when coding, try stuff just to see if it works because I can't form a clear picture of the data scope. And that would probably walk me right into the type of issue you're describing too...
I've just checked a few of my mods with api calls and it looks like I don't have any cases like this, but I see how it could happen very easily. For example:
I think you're saying that last part might blow up because we've left the context of the first block where the api call was made, and the reference may have been flushed. And that even this is risky: