Skip to content

Conversation

@oznogon
Copy link
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
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
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
@oznogon oznogon requested a review from daid December 8, 2025 16:44
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