Skip to content

Comments

Fix Lua API issues#2718

Open
oznogon wants to merge 21 commits intodaid:masterfrom
oznogon:fix-lua-api-issues
Open

Fix Lua API issues#2718
oznogon wants to merge 21 commits intodaid:masterfrom
oznogon:fix-lua-api-issues

Conversation

@oznogon
Copy link
Contributor

@oznogon oznogon commented Feb 14, 2026

  • Fix broken string.sub() calls re: model data that forget to pass the string into the function's first argument
  • Add missing coordinate arguments to ModelData:addTubePosition()
  • Use the offset_x/_y arguments passed to orderFlyFormation() instead of invalid globals x/y
  • Fix deprecated shield functions' dot/colon notation
  • Fix broken ScienceDatabase hasEntries(), which still doesn't work as documented anyway due to [Regression] getScienceDatabases() global no longer exists #2615 / [#2615] Attempt to restore getScienceDatabases() function #2617
  • Use deepcopy() to copy modelData by value for ScienceDatabase:setModelDataName(), aligned with other uses of deepcopy() for modelData
  • Fix DockingPort state enum converter incorrectly using copied/pasted Comms values (use docking instead of opening, docked instead of hailed)
  • Fix setPlanetCloudRadius(), warpjammer get/setRange() missing components reference
  • Replace incorrect spin with function argument rotation_time in planet setAxialRotationTime()
  • Remove unused hailed_player state in isCommsBeingHailed()
  • Fix spaceship addBroadcast() color assignments; hostile is gray and neutral is red
  • Validate tube index on spaceship get/setWeaponTube...() functions
  • Fix broken value validation in spaceobject take/addReputationPoints()
  • Fix function chaining in stbo setRadarTrace()
  • Validate mesh_render.scale is present before using values in addEngineEmitter()
  • Clamp spaceobject getHeading() to 0-360 range
  • Fix orderFlyFormation() assigning a different case to the order string than the enum

oznogon and others added 19 commits February 14, 2026 13:10
Lua pairs loops for model data include a string.sub() call to
ignore keys starting with two underscores (__).

    for k, v in pairs(__model_data[model]) do
        if string.sub(1, 2) ~= "__" then
            ...

However, instead of passing the key string in the first argument,
which expects the string to substring, this passes the position
index of 1. So instead of checking as expected:

    string.sub("__some_string", 1, 2) ~= "__"

It effectively checks:

    string.sub("1", 2) ~= "__"

which is always true.

Fix this by passing the key in the string.sub() call.
ModelData:addTubePosition() doesn't accept any arguments, when it
should accept x, y, and z coordinates, the same as
addBeamPosition(). Add the missing arguments.
AIController ship Lua function orderFlyFormation() takes two
arguments, offset_x and offset_y, but doesn't use them. It instead
uses x and y, which are valid globals with unexpected or nil
values when this function is called.

Use the offset values passed to the function.
Also, fix the broken ScienceDatabase hasEntries() function, which
attempts to call an undefined global getEntries() function instead
of self:getEntries().
Reject negative argument values. Remove a broken validation
Boolean from addReputationPoints() that seemed to check against
subtracting too many points, but nearly always returned an
incorrect value of true.
function Entity:setHeading(heading)
if self.components.transform then self.components.transform.rotation = heading + 270 end
if self.components.transform then
local heading = self.components.transform.rotation + 270
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, as it's not taking the parameter passed but the current rotation.

Copy link
Contributor Author

@oznogon oznogon Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote both to use modulo in 3f4dfb9.

> player=getPlayerShip(-1)
> player:getHeading()
193.6946105957
> player:setHeading(540)
entity: 0xce
> player:getHeading()
180.0
> player:setHeading(0)
entity: 0xce
> player:getHeading()
0.0
> player:setHeading(-90)
entity: 0xce
> player:getHeading()
270.0

@oznogon oznogon requested a review from daid February 21, 2026 19:32
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