Question THGROUP_USER / THGROUP.USER Identifier in Lua?

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
Hi, me again :)

I wanted to verify if the THGROUP_USER identifier was ported to Lua or not. It is not shown in the listing of thruster group identifiers in the Help pages:

Screenshot at 2023-11-10 11-49-20.png
My jet engine code requires a user-defined thruster group, so if it doesn't exist I'll have to cobble something else together.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
I am pretty sure it is. In general it's just another Number used to identify the thruster group(s) - 0x40 to be exact.
And it's clearly handled in "\Module\LuaScript\LuaInterpreter\lua_vessel_mtd.cpp":
C++:
//...
int Interpreter::v_create_thrustergroup (lua_State *L)
{
    static const char *funcname = "create_thrustergroup";
    AssertMtdMinPrmCount(L, 2, funcname);
    VESSEL *v = lua_tovessel_safe(L, 1, funcname);
    AssertMtdPrmType(L, 2, PRMTP_TABLE, funcname);
    THGROUP_TYPE thgt;
    if (lua_gettop(L) >= 3) {
        thgt = (THGROUP_TYPE)luamtd_tointeger_safe(L, 3, funcname);
    } else {
        thgt = THGROUP_USER;
    }

    // traverse the thruster array
    static int nht = 1;
    static THRUSTER_HANDLE *ht = new THRUSTER_HANDLE[nht];

    lua_pushnil(L);
    int i = 0;
    while (lua_next(L,2)) {
        if (i >= nht) {
            THRUSTER_HANDLE *tmp = new THRUSTER_HANDLE[i+1];
            memcpy(tmp, ht, nht*sizeof(THRUSTER_HANDLE));
            delete []ht;
            ht = tmp;
            nht = i+1;
        }
        ht[i++] = (THRUSTER_HANDLE)lua_touserdata(L,-1);
        lua_pop(L,1);
    }
    lua_pop(L,1);
    THGROUP_HANDLE htg = v->CreateThrusterGroup (ht, i, thgt);
    lua_pushlightuserdata(L,htg);
    return 1;
}
//...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
It does appear that THGROUP.USER does exist as I have my jet engine code working with it. It didn't play nice with my afterburner thruster group (originally THGROUP_USER) in that appears to override the THGROUP.USER definition for my throttle thruster. It seems that I can only have one instance of a THGROUP.USER thruster group. But if I just manipulate the afterburner thruster directly there is no conflict.
 
Top