Skip to content

[#2615] Attempt to restore getScienceDatabases() function#2617

Merged
daid merged 6 commits intodaid:masterfrom
oznogon:restore-getScienceDatabases
Mar 12, 2026
Merged

[#2615] Attempt to restore getScienceDatabases() function#2617
daid merged 6 commits intodaid:masterfrom
oznogon:restore-getScienceDatabases

Conversation

@oznogon
Copy link
Copy Markdown
Contributor

@oznogon oznogon commented Dec 1, 2025

Attempts to address #2615 by having getParentId() return 0 if the ScienceDatabase entry entity lacks a parent, and then restoring getScienceDatabases() to return a table of all unparented entry entities.

> sdb = getScienceDatabases()
> sdb[1]
entity: 0xa
> sdb[1]:getName()
Natural
> sdb[1]:getParentId()
0 -- legacy-compatible response for entry with no parent
> sdb[1]:getEntries()
table: 0x13af1270
> sdb[1]:getEntries()[1]
entity: 0xb -- first child entry of Natural
> sdb[1]:getEntries()[1]:getName()
Asteroid
> sdb[1]:getEntries()[1]:getParentId()
entity: 0xa

This also fixes hasEntries(), which attempts to call a global getEntries() instead of self:getEntries() for the count.

Before:

> getScienceDatabases()[1]:hasEntries()
api/entity/sciencedatabase.lua:119: attempt to call a nil value (global 'getEntries')
stack traceback:

After:

> getScienceDatabases()[1]:hasEntries()
true

@oznogon
Copy link
Copy Markdown
Contributor Author

oznogon commented Dec 1, 2025

In ECS/master, it's unclear how to handle when an entity-type property like components.science_database.parent contains an empty entity. In C++, this is equivalent to an empty sp::ecs::Entity(). In Lua, these entities stringify as 0xffffffffffffffff (32-bit unsigned integer max).

In Lua, creating an empty entity such as local nothing = createEntity() still creates a valid entity with an entity ID and doesn't match the value of an empty entity. Matching by stringified entity ID entity: 0xffffffffffffffff isn't a good idea.

@oznogon
Copy link
Copy Markdown
Contributor Author

oznogon commented Dec 2, 2025

Thanks to @GinjaNinja32, isValid() returns false for these empty entities.

@oznogon oznogon marked this pull request as ready for review December 2, 2025 04:01
Comment thread scripts/api/entity/sciencedatabase.lua Outdated
@oznogon oznogon requested a review from daid December 8, 2025 16:44
@oznogon oznogon changed the title Attempt to restore getScienceDatabases() function [#2615] Attempt to restore getScienceDatabases() function Feb 14, 2026
@daid daid merged commit 559138a into daid:master Mar 12, 2026
5 checks passed
@oznogon oznogon deleted the restore-getScienceDatabases branch March 12, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants