Modding Help entityQuery returns empty field

Discussion in 'Starbound Modding' started by Okaghana, Dec 31, 2019.

  1. Okaghana

    Okaghana Space Hobo

    Hey guys.

    So I'm currently developing a mod, that modifies the MM to mine faster is you are shifting (basically you are focusing the "mining-energy" on a single Block). I opened the beamaxe.lua file (under ./items/tools/miningtools) which is responsible for the MM. Important here is the notifyEntities-function, which notifies the entities that you are currently hovering (and therefore currently mining/removing/reaping/etc.) and basically tells them, that they are mined and therefore triggering a response:

    Code:
    function notifyEntities(shifting)
      local entities = world.entityQuery(fireableItem.ownerAimPosition(), shifting and self.altRadius or self.radius, self.notifyQueryParams)
      for _, entityId in ipairs(entities) do
        world.sendEntityMessage(entityId, "positionTileDamaged", self.notifyDamage)
      end
    end
    Just for clarity: Fetch the Entities in range -> loop over them -> tell everyone, that they are mined

    For my mod I added another property to the MM called self.speedboost and before I send the Message to the Entity, I multiply the self.notifyDamage by this boost and sending it instead:

    Code:
    damage = self.notifyDamage
    if shifting then
        damage = damage * self.speedboost
    end
    Now here comes the problem: This Multiplication is never applied, because world.entityQuery" returns an empty field. For this I logged the entities variable after converting it. End the result is an empty
    Code:
    {}
    in the log.

    Why exactly is that? Does entityQuery not apply to Blocks and therefore i get an empty table back? And if so: where is the code, that handles the mining of blocks?

    I also tried to e.g. click a (grown) plant, but the returned table is still empty :(

    Do you have any Idea what is going wrong?

    ~Okaghana

    P.S.: Just out of curiosity: When I alter for example the notifyEntities-function, and another mod alteres the init-function, but not the notifyEntities-function: Does the loading of the other mod after the loading of mine override my altered function, or does the mod-loader only override the functions, that were altered by the mod?
    Also: Could I therefore in a file only add my altered notifyEntities-function and exclude the others, and the mod-loader would automatically fetch the original functions from the base-game?
     
  2. bk3k

    bk3k Oxygen Tank

    blocks are indeed not entities. There are a number of functions in the world table that can detect tiles, but entityQuery is not one of them. And world.damageTiles is what you'd probably want to use in order to break tiles.
    Code:
    ---
    
    #### `bool` world.damageTiles(`List<Vec2I>` positions, `String` layerName, `Vec2F` sourcePosition, `String` damageType, `float` damageAmount, [`unsigned` harvestLevel], [`EntityId` sourceEntity])
    
    Damages all tiles in the specified layer and positions by the specified amount. The source position of the damage determines the initial direction of the damage particles. Damage types are: "plantish", "blockish", "beamish", "explosive", "fire", "tilling". Harvest level determines whether destroyed materials or mods will drop as items. Returns `true` if any damage was done and `false` otherwise.
    
    ---
    edit:
    strictly speaking, you don't truly need to detect the tiles for what you are doing. You instead probably want to build a table of locations. to send based of the cursor location. Then send the tile damage request.


    Also to make that easy
    Code:
    local add
    local translate_locations
    
    add = function (t1, t2)
      return {(t1[1] + t2[1]), (t1[2] + t2[2])}
    end
    
    translate_locations = function(position, offsets)
      local r = {}
      for k, v in ipairs(offsets) do
        r[k] = world.xwrap( add(position, v) )
      end
      return r
    end
     
    Last edited by a moderator: Jan 2, 2020
  3. Okaghana

    Okaghana Space Hobo

    OK. But my Problem with the approach is, that you are basically mining in 2 places in the code: The original Code and the added Code to the Script. I have no doubt that it could work that way, but I thinks its kinda ugly and bodgy. I would prefer a clean solution, were you just edit the original code. Now my Question is: Because the Mining is not handled by the beamaxe.lua file, where is it handled? Can you even Change the mining-behavior, or is the mining hard-coded in the gamefiles and can't be changed by mods?
     
  4. bk3k

    bk3k Oxygen Tank

    The beamaxe is a hardcoded. The "configuration" of it actually replaces the one you have with another beamaxe with alternate JSON properties.

    That said, world.damageTiles is versatile enough. You can control the amount of damage you where going to do in the same way. If they are "shifting" (holding <shift> I assume), then you feel it a table of coordinates which only has one element (the cursor position) and increase the damage accordingly. If not, you calculate the total area, and send less damage to the whole thing. That matches what I assume your intent to be.
     
  5. Okaghana

    Okaghana Space Hobo

    Hello There Again.

    I tried to Implement the Mining of Blocks in the update-Function of the beamaxe.lua file. Here is my code:
    Code:
    if shifting and fireMode ~= "none" then
        position = fireableItem.ownerAimPosition()
        world.damageTiles({position}, "foreground" and fireMode == "primary" or "background", position, "blockish", self.tileDamage, 0)
      end
    But I keep getting this strange Error Message:
    Code:
    [00:07:44.776] [Error] Exception while invoking lua function 'update'. (LuaException) Error code 2, [string "/items/tools/miningtools/beamaxe.lua"]:24: (LuaConversionException) Error converting LuaValue to type 'class Star::String'
    [0] 13fb9a213 Star::captureStack
    [1] 13fb98f9e Star::StarException::StarException
    [2] 13fb63b8b Star::LuaConversionException::LuaConversionException
    [3] 13fb602e6 Star::LuaConversionException::format<char const * __ptr64>
    [4] 13fc78eed Star::LuaEngine::luaTo<Star::String>
    [5] 13fc7e771 Star::LuaDetail::ArgGet<Star::String>::get
    [6] 14026523c <lambda_9ec45fd858bfb592580f15c48564bd1b>::operator()
    [7] 14022ee7f std::_Invoker_functor::_Call<<lambda_9ec45fd858bfb592580f15c48564bd1b> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [8] 1402460e0 std::invoke<<lambda_9ec45fd858bfb592580f15c48564bd1b> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [9] 14023739b std::_Invoke_ret<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,<lambda_9ec45fd858bfb592580f15c48564bd1b> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [10] 14026e1ab std::_Func_impl<<lambda_9ec45fd858bfb592580f15c48564bd1b>,std::allocator<int>,Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::_Do_call
    [11] 13fb6733d std::_Func_class<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::operator()
    [12] 13fb666d7 <lambda_894500e69fe9ecf0c3703bede71c72aa>::operator()
    [13] 13faf3158 luaD_precall
    [14] 13fb0bf01 luaV_execute
    [15] 13faf2c63 luaD_call
    [16] 13faf343b luaD_rawrunprotected
    [17] 13faf2e70 luaD_pcall
    [18] 13fae9404 lua_pcallk
    [19] 13fb6e630 Star::LuaEngine::pcallWithTraceback
    [20] 140162731 Star::LuaEngine::callFunction<float,Star::String,bool>
    [21] 140162d58 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,float,Star::String,bool>
    [22] 140162c7e Star::LuaBaseComponent::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,float const & __ptr64,Star::String const & __ptr64,bool & __ptr64>
    [23] 1401644d2 Star::FireableItem::update
    [24] 140198d9d Star::BeamMiningTool::update
    [25] 140018880 Star::ToolUser::tick
    [26] 13fe8c8cb Star::Player::update
    [27] 1400a3648 <lambda_9fc580ae40b93070d912cafafa15880e>::operator()
    [28] 13fce3846 Star::EntityMap::updateAllEntities
    [29] 1400bc15b Star::WorldClient::update
    [30] 1400269bd Star::UniverseClient::update
    [31] 13fae5da7 Star::ClientApplication::updateRunning
    [32] 13fae473d Star::ClientApplication::update
    [33] 1402ad4d1 Star::SdlPlatform::run
    [34] 1402ad68d Star::runMainApplication
    [35] 13fae7731 WinMain
    [36] 1404907af __scrt_common_main_seh
    [37] 77a4556d BaseThreadInitThunk
    [38] 77ba372d RtlUserThreadStart
    stack traceback:
        [C]: in ?
        [C]: in field 'damageTiles'
        [string "/items/tools/miningtools/beamaxe.lua"]:24: in function <[string "/items/tools/miningtools/beamaxe.lua"]:19>
    [0] 13fb9a213 Star::captureStack
    [1] 13fb98f9e Star::StarException::StarException
    [2] 13fb6cfb1 Star::LuaEngine::handleError
    [3] 14016274a Star::LuaEngine::callFunction<float,Star::String,bool>
    [4] 140162d58 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,float,Star::String,bool>
    [5] 140162c7e Star::LuaBaseComponent::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::LuaString,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,float const & __ptr64,Star::String const & __ptr64,bool & __ptr64>
    [6] 1401644d2 Star::FireableItem::update
    [7] 140198d9d Star::BeamMiningTool::update
    [8] 140018880 Star::ToolUser::tick
    [9] 13fe8c8cb Star::Player::update
    [10] 1400a3648 <lambda_9fc580ae40b93070d912cafafa15880e>::operator()
    [11] 13fce3846 Star::EntityMap::updateAllEntities
    [12] 1400bc15b Star::WorldClient::update
    [13] 1400269bd Star::UniverseClient::update
    [14] 13fae5da7 Star::ClientApplication::updateRunning
    [15] 13fae473d Star::ClientApplication::update
    [16] 1402ad4d1 Star::SdlPlatform::run
    [17] 1402ad68d Star::runMainApplication
    [18] 13fae7731 WinMain
    [19] 1404907af __scrt_common_main_seh
    [20] 77a4556d BaseThreadInitThunk
    [21] 77ba372d RtlUserThreadStart
    I think something about my parameters is wrong, but I don't know what :(
     
  6. Errors4l

    Errors4l Spaceman Spiff

    "foreground" and fireMode == "primary" or "background"
    Swap the first two parts.
    fireMode == "primary" and "foreground" or "background"
     

Share This Page