[Question] Using SobGroup_GetShipType()

Hi All,

Trying to do something simple (or so I thought) with the custom code. To help with tracking what the AI is doing in a match I wanted to add a built/destroyed statement to a ship. There are 21 examples of SobGroup_GetShipType() in the default game files over 4 different files. The examples are possibly being fed data from somewhere I can’t locate because following them has resulted in the following:

fed_TOS_flagship.lua

addCustomCode(NewShipType,“data:scripts/continuum/stc_starship.lua”,"",“Create_STC_Starship”,“Update_STC_Starship”,“Destroy_STC_Starship”,“fed_TOS_flagship”, 0.01)

stc_starship.lua

dofilepath(“data:scripts/continuum/lib/stc_warp.lua”)
dofilepath(“data:scripts/continuum/lib/stc_logging.lua”)

function Create_STC_Starship(CustomGroup, playerIndex, shipID)

Create_WarpShip(CustomGroup, playerIndex, shipID)
ReportConstruction(CustomGroup, playerIndex)

end

function Update_STC_Starship(CustomGroup, playerIndex, shipID)

Update_WarpShip(CustomGroup, playerIndex, shipID)

end

function Destroy_STC_Starship(CustomGroup, playerIndex, shipID)

ReportDestruction(CustomGroup, playerIndex)

end

stc_logging.lua

function ReportConstruction(CustomGroup, playerIndex)

local shipType = SobGroup_GetShipType(CustomGroup)
print(">> CONSTRUCTION >> | Player “…playerIndex…” has built a "…shipType)

end

function ReportDestruction(CustomGroup, playerIndex)

local shipType = SobGroup_GetShipType(CustomGroup)
print(">> DESTRUCTION >> | Player “…playerIndex…” has lost a "…shipType)

end

HwRM.log

luasobgroupquery 3082: SobGroup_GetShipType: nothing in sobgroup (fed_TOS_flagship)
parameter: bad argument #1 to `?’ (string expected, got table)
parameter: unable to recover; exiting
Lua – Critical error – FATAL EXIT – luamem/103:! --stack trace–

Not sure why this is happening, if anyone who can clarify why grabbing the ship type from the CustomGroup doesn’t work that would be appreciated. Also, from this, it appears that the CustomGroup gets the name that you give to the final text parameter in the addCustomCode statement

I think it’s because your second function (in stc_logging.lua) is actually checking the ship type of the group after the ship has been destroyed, so the group is empty… I’d suggest checking the ship type on creation and storing it as a variable.

1 Like
ships = {}

function OnCreate(CustomGroup, playerIndex, shipID)
    ships[shipID] = {}
    ships[shipID].playerIndex = playerIndex
    ships[shipID].shipType = SobGroup_GetShipType(CustomGroup)
end

function OnDestroy(CustomGroup, playerIndex, shipID)
    -- do whatever with ships[shipID]
end

Specifically, it’s the name of the SobGroup that contains that ship.

2 Likes

Looks like, while you know what you’re doing, and that syntax is correct, that in OnCreate and OnDestroy the sobGroup is just not filled at all :confused:

parameter: table index is nil
stack traceback:
1: function ReportConstruction' at line 5 [string ""] 2: functionCreate_STC_Starship’ at line 8 [string “”]

Is it possible to just pull the name of the SOBgroup? That would work just as well…

Why not add _ALERT(CustomGroup) and see what you get?

The argument CustomGroup is the name of the SOBGroup.

Do you have an example I can work from?

It is yes, but it is dynamically renamed to the last text parameter in the addCustomCode statement, which is the very text I was wanting to put into a print statement, but I’ve not seen any functions that will let you put the name of a SOB Group into a print statement.

I’m pretty sure

print("My SOBGroup is called "..CustomGroup)

would do it. Or perhaps I am missing the point…

I just don’t know this sort of thing :sweat_smile:

I’ll try that when I get home! Unfortunately I just started my Monday morning :confused:


Yes, @Dom2 is correct.

3 Likes

Basically, _ALERT() function does the same thing as print() does. So _ALERT(CustomGroup) will simply write the name of your ship to your log.

1 Like