Modding Help Quest Lua not working properly

Discussion in 'Starbound Modding' started by projectmayhem, May 2, 2017.

  1. projectmayhem

    projectmayhem Spaceman Spiff

    Ok here is the entire LUA, ill point out the part I cant get right below.


    Code:
    require "/scripts/util.lua"
    require "/scripts/vec2.lua"
    require "/quests/scripts/portraits.lua"
    require "/quests/scripts/questutil.lua"
    
    function init()
      setPortraits()
    
      storage.complete = storage.complete or false
    
      self.compassUpdate = config.getParameter("compassUpdate", 0.5)
    
      storage.stage =  1
      self.stages = {
        turnIn   
      }
    
      self.state = FSM:new()
      self.state:set(self.stages[storage.stage])
    end
    
    function questInteract(entityId)
      if self.onInteract then
        return self.onInteract(entityId)
      end
    end
    
    function questStart()
      player.enableMission(config.getParameter("associatedMission"))
    end
    
    
    function questComplete()
      setPortraits()
      questutil.questCompleteActions()
    end
    
    
    function turnIn()
      quest.setIndicators({})
      quest.setCompassDirection(nil)
      quest.setObjectiveList({{config.getParameter("descriptions.turnIn"), false}})
      quest.setCanTurnIn(true)
    
      local findJedi = util.uniqueEntityTracker(self.jediUid, self.compassUpdate)
      while storage.stage == 1 do
        questutil.pointCompassAt(findJedi())
        coroutine.yield()
      end
    end
    


    With the code like that, I get an error at line 20 which is :
    self.state:set(self.stages[storage.stage])

    The error says:
    [C]: in ?
    [C]: in field 'state'
    [string "/scripts/util.lua"]:868: in method 'set'

    Full Error log here:

    Code:
    [19:15:04.555] [Error] Exception while calling script init: (LuaException) Error code 2, [string "/scripts/util.lua"]:868: [string "/quests/scripts/jedi/jeditemple.lua"]:49: [string "/scripts/util.lua"]:297: (LuaConversionException) Error converting LuaValue to type 'class Star::String'
    [0] 13f6d3d13 Star::captureStack
    [1] 13f6d2a9e Star::StarException::StarException
    [2] 13f69f37b Star::LuaConversionException::LuaConversionException
    [3] 13f69abf6 Star::LuaConversionException::format<char const * __ptr64>
    [4] 13f79b1f5 Star::luaTo<Star::String>
    [5] 13f7a2284 Star::LuaDetail::ArgGet<Star::String>::get
    [6] 13fd45576 <lambda_d05c3a92049702c8f71ee1e8b1fd68d5>::operator()
    [7] 13fd117bf std::_Invoker_functor::_Call<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [8] 13fd272d0 std::invoke<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [9] 13fd1a449 std::_Invoke_ret<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [10] 13fd4b9eb std::_Func_impl<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5>,std::allocator<int>,Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::_Do_call
    [11] 13f6a210d std::_Func_class<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::operator()
    [12] 13f6a11a4 <lambda_a03bcae4599b53751a446949639a4d5e>::operator()
    [13] 13f62b528 luaD_precall
    [14] 13f6442d1 luaV_execute
    [15] 13f62b80b luaD_rawrunprotected
    [16] 13f62bb2f lua_resume
    [17] 13f62888f auxresume
    [18] 13f628950 luaB_auxwrap
    [19] 13f62b528 luaD_precall
    [20] 13f6442d1 luaV_execute
    [21] 13f62b80b luaD_rawrunprotected
    [22] 13f62bb2f lua_resume
    [23] 13f62888f auxresume
    [24] 13f628950 luaB_auxwrap
    [25] 13f62b528 luaD_precall
    [26] 13f6442d1 luaV_execute
    [27] 13f62b033 luaD_call
    [28] 13f62b80b luaD_rawrunprotected
    [29] 13f62b240 luaD_pcall
    [30] 13f621754 lua_pcallk
    [31] 13f6a9110 Star::LuaEngine::pcallWithTraceback
    [32] 13f8745c4 Star::LuaEngine::callFunction<>
    [33] 13f877e71 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [34] 13fcbef03 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [35] 13fcc08c7 Star::LuaBaseComponent::init
    [36] 13fa39b7e Star::Quest::initScript
    [37] 13fa1ae5e Star::QuestManager::init
    [38] 13f9a8abb Star::Player::init
    [39] 13fbaa3cd Star::WorldClient::initWorld
    [40] 13fba85bf Star::WorldClient::handleIncomingPackets
    [41] 13fb2bbed Star::UniverseClient::handlePackets
    [42] 13fb2cf01 Star::UniverseClient::update
    [43] 13f61e2d8 Star::ClientApplication::updateRunning
    [44] 13f61cc1f Star::ClientApplication::update
    [45] 13fd8f481 Star::SdlPlatform::run
    [46] 13fd8f78d Star::runMainApplication
    [47] 13f61fd76 WinMain
    [48] 13ff757a3 __scrt_common_main_seh
    [49] 771e59cd BaseThreadInitThunk
    [50] 7731a561 RtlUserThreadStart
    stack traceback:
        [C]: in ?
        [C]: in field 'state'
        [string "/scripts/util.lua"]:868: in method 'set'
        [string "/quests/scripts/jedi/jeditemple.lua"]:20: in function <[string "/quests/scripts/jedi/jeditemple.lua"]:6>
    [0] 13f6d3d13 Star::captureStack
    [1] 13f6d2a9e Star::StarException::StarException
    [2] 13f6a7cd1 Star::LuaEngine::handleError
    [3] 13f8745dd Star::LuaEngine::callFunction<>
    [4] 13f877e71 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [5] 13fcbef03 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [6] 13fcc08c7 Star::LuaBaseComponent::init
    [7] 13fa39b7e Star::Quest::initScript
    [8] 13fa1ae5e Star::QuestManager::init
    [9] 13f9a8abb Star::Player::init
    [10] 13fbaa3cd Star::WorldClient::initWorld
    [11] 13fba85bf Star::WorldClient::handleIncomingPackets
    [12] 13fb2bbed Star::UniverseClient::handlePackets
    [13] 13fb2cf01 Star::UniverseClient::update
    [14] 13f61e2d8 Star::ClientApplication::updateRunning
    [15] 13f61cc1f Star::ClientApplication::update
    [16] 13fd8f481 Star::SdlPlatform::run
    [17] 13fd8f78d Star::runMainApplication
    [18] 13f61fd76 WinMain
    [19] 13ff757a3 __scrt_common_main_seh
    [20] 771e59cd BaseThreadInitThunk
    [21] 7731a561 RtlUserThreadStart
    [19:15:04.964] [Info] APPLICATION TIMERS
    [19:15:04.964] [Info] Update: 0.238629
    [19:15:04.964] [Info] ProcessInput: 6.09481e-06
    [19:15:04.964] [Info] PlatformServices: 6.41681e-07
    [19:15:04.964] [Info] Render: 0.387611
    [19:15:04.964] [Info] FullUpdate: 0.626253
    [19:15:36.674] [Error] Exception while calling script init: (LuaException) Error code 2, [string "/scripts/util.lua"]:868: [string "/quests/scripts/jedi/jeditemple.lua"]:49: [string "/scripts/util.lua"]:297: (LuaConversionException) Error converting LuaValue to type 'class Star::String'
    [0] 13f6d3d13 Star::captureStack
    [1] 13f6d2a9e Star::StarException::StarException
    [2] 13f69f37b Star::LuaConversionException::LuaConversionException
    [3] 13f69abf6 Star::LuaConversionException::format<char const * __ptr64>
    [4] 13f79b1f5 Star::luaTo<Star::String>
    [5] 13f7a2284 Star::LuaDetail::ArgGet<Star::String>::get
    [6] 13fd45576 <lambda_d05c3a92049702c8f71ee1e8b1fd68d5>::operator()
    [7] 13fd117bf std::_Invoker_functor::_Call<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [8] 13fd272d0 std::invoke<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [9] 13fd1a449 std::_Invoke_ret<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,<lambda_d05c3a92049702c8f71ee1e8b1fd68d5> & __ptr64,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>
    [10] 13fd4b9eb std::_Func_impl<<lambda_d05c3a92049702c8f71ee1e8b1fd68d5>,std::allocator<int>,Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::_Do_call
    [11] 13f6a210d std::_Func_class<Star::Variant<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData>,Star::LuaVariadic<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> > >,Star::LuaEngine & __ptr64,unsigned __int64,Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> * __ptr64>::operator()
    [12] 13f6a11a4 <lambda_a03bcae4599b53751a446949639a4d5e>::operator()
    [13] 13f62b528 luaD_precall
    [14] 13f6442d1 luaV_execute
    [15] 13f62b80b luaD_rawrunprotected
    [16] 13f62bb2f lua_resume
    [17] 13f62888f auxresume
    [18] 13f628950 luaB_auxwrap
    [19] 13f62b528 luaD_precall
    [20] 13f6442d1 luaV_execute
    [21] 13f62b80b luaD_rawrunprotected
    [22] 13f62bb2f lua_resume
    [23] 13f62888f auxresume
    [24] 13f628950 luaB_auxwrap
    [25] 13f62b528 luaD_precall
    [26] 13f6442d1 luaV_execute
    [27] 13f62b033 luaD_call
    [28] 13f62b80b luaD_rawrunprotected
    [29] 13f62b240 luaD_pcall
    [30] 13f621754 lua_pcallk
    [31] 13f6a9110 Star::LuaEngine::pcallWithTraceback
    [32] 13f8745c4 Star::LuaEngine::callFunction<>
    [33] 13f877e71 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [34] 13fcbef03 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [35] 13fcc08c7 Star::LuaBaseComponent::init
    [36] 13fa39b7e Star::Quest::initScript
    [37] 13fa3ae25 Star::Quest::offer
    [38] 13f9b28f4 Star::Player::triggerPickupEvents
    [39] 13f9ab58a Star::Player::pickupItems
    [40] 13fbb2215 Star::WorldClient::tryGiveMainPlayerItem
    [41] 13fba921c Star::WorldClient::handleIncomingPackets
    [42] 13fb2bbed Star::UniverseClient::handlePackets
    [43] 13fb2cf01 Star::UniverseClient::update
    [44] 13f61e2d8 Star::ClientApplication::updateRunning
    [45] 13f61cc1f Star::ClientApplication::update
    [46] 13fd8f481 Star::SdlPlatform::run
    [47] 13fd8f78d Star::runMainApplication
    [48] 13f61fd76 WinMain
    [49] 13ff757a3 __scrt_common_main_seh
    [50] 771e59cd BaseThreadInitThunk
    [51] 7731a561 RtlUserThreadStart
    stack traceback:
        [C]: in ?
        [C]: in field 'state'
        [string "/scripts/util.lua"]:868: in method 'set'
        [string "/quests/scripts/jedi/jeditemple.lua"]:20: in function <[string "/quests/scripts/jedi/jeditemple.lua"]:6>
    [0] 13f6d3d13 Star::captureStack
    [1] 13f6d2a9e Star::StarException::StarException
    [2] 13f6a7cd1 Star::LuaEngine::handleError
    [3] 13f8745dd Star::LuaEngine::callFunction<>
    [4] 13f877e71 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [5] 13fcbef03 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [6] 13fcc08c7 Star::LuaBaseComponent::init
    [7] 13fa39b7e Star::Quest::initScript
    [8] 13fa3ae25 Star::Quest::offer
    [9] 13f9b28f4 Star::Player::triggerPickupEvents
    [10] 13f9ab58a Star::Player::pickupItems
    [11] 13fbb2215 Star::WorldClient::tryGiveMainPlayerItem
    [12] 13fba921c Star::WorldClient::handleIncomingPackets
    [13] 13fb2bbed Star::UniverseClient::handlePackets
    [14] 13fb2cf01 Star::UniverseClient::update
    [15] 13f61e2d8 Star::ClientApplication::updateRunning
    [16] 13f61cc1f Star::ClientApplication::update
    [17] 13fd8f481 Star::SdlPlatform::run
    [18] 13fd8f78d Star::runMainApplication



    This error is keeping the mission from showing up on the SAIL menu. If I delete the word "set" from that line, the mission shows up, but nothing else works. I can warp there, but the Turn in NPC doesn't have a blue ? mark and my quest tracker doesn't show any text, just an empty box.

    With the set in there though, the mission wont show up on SAIL, but if I /warp instanceworld:jeditemple then the turn in works fine. So what am I doing wrong?
     
  2. bk3k

    bk3k Oxygen Tank

    Code:
    [Error] Exception while calling script init: (LuaException) Error code 2, [string "/scripts/util.lua"]:868: [string "/quests/scripts/jedi/jeditemple.lua"]:49: [string "/scripts/util.lua"]:297: (LuaConversionException) Error converting LuaValue to type 'class Star::String'
    Lets unwind that a bit
    Code:
    (LuaConversionException) Error converting LuaValue to type 'class Star::String'
    
    This means it needs a string, and it got something which cannot be converted to a string. LuaValue represent any data type that is valid in LUA.
    boolean
    number (I believe this would convert)
    table
    string (obviously this would convert to a C string)
    function
    userdata
    thread
    nil

    I've seen this most often because something received nil rather than what it needed. But possibly you have a table improperly nested and thus you sent a table.

    Next lets look at the rest
    Code:
    [string "/scripts/util.lua"]:868:
    [string "/quests/scripts/jedi/jeditemple.lua"]:49:
    [string "/scripts/util.lua"]:297:
    
    This is tracing back what got called, and what function called it. More specifically one function calling another (needing the return to continue), and that function calling yet another. Look well at what arguments are being passed by your script's line 49, and then look at where it got that data, and what might have been done to that data since.

    I think you're going to want to do some strategic placing of debugger code in your script. Dumping strings is easy enough, but in case you need to dump tables I'll give you something I made that I think is sort of nice.


    Code:
    makeString = function(someTable, baseName, str)--debug purposes only
      str = str or ""
      for k, v in pairs(someTable) do
        if type(v) == "table" then
          if ( function(v) for _, __ in pairs(v) do return false end return true end ) then
            str = str .. baseName .. "." .. tostring(k) .. " : { }\n"
          elseif (#v == 2) and (type(v[1]) == "number") and (type(v[2]) == "number") then  --coordinate table
            str = str .. baseName .. "." .. tostring(k) .. " : {" .. v[1] .. ", " .. v[2]  .. "}\n"
          else
            str = str .. makeString(v , baseName .. "." .. tostring(k), "") --.. "\n"
            --recursive calls don't necessarily need the original string because the main function will still have it
          end
      
        elseif (type(v) == "string") then
          str = str .. baseName .. "." .. tostring(k) .. " : \"" .. v .. "\"\n"
        elseif not (type(v) == "function") then
          str = str .. baseName .. "." .. tostring(k) .. " : " .. tostring(v) .. "\n"
        end
      end
    
      return str
    end
    
    It accepts 3 arguments
    1. The table you want to look at.
    2. A string that generally should reflect the table's name because otherwise your log might not make much sense.
    3. A string that goes at the beginning of the return. The rest of the results would be appended to this. Totally optional but nice if you had some previous results that you are adding onto. Or a note of some sort - perhaps telling you some specific context involved like a seed used, what function/line/etc you're currently at, etc.

    It returns a string. Sometimes a very long string.

    This function is recursive - it calls itself to handle nested tables.
    Because of the intended purpose of this function, it ignores functions within tables. I have other things for function dumps.

    A sample use looks like this
    Code:
    local dump = makeString(myTable, "myTable", "\n")
    sb.logInfo(dump)
    
    or
    Code:
    local dump = makeString(storage, "storage", "\ncalled from end of init\n")
    sb.logInfo(dump)
    
    generally good targets include the self and storage tables, but anything you need to see a readout of.

    An example log readout where I'm using this for a particular project.

    Code:
    [05:09:32.460] [Info]
    ------begin_damageRequest------(
    --applyDamageRequest called
    applyDamageRequest.damageSourceKind : falling
    applyDamageRequest.damage : 43.63330078125
    
    applyDamageRequest.hitType : Hit
    applyDamageRequest.damageType : IgnoresDef
    applyDamageRequest.sourceEntityId : -65536
    applyDamageRequest.knockbackMomentum : {0.0, 0.0}
    
    
    --Modified damageRequest
    applyDamageRequest.damageSourceKind : falling
    applyDamageRequest.damage : 0
    
    applyDamageRequest.hitType : Hit
    applyDamageRequest.damageType : IgnoresDef
    applyDamageRequest.sourceEntityId : -65536
    applyDamageRequest.knockbackMomentum : {0.0, 0.0}
    
    
    sT_dF.moved : {0.1561279296875, -0.4708251953125}
    sT_dF.lastVelocity : {9.3649082183838, -49.088359832764}
    sT_dF.velocity : {5.9506182670593, -19.221548080444}
    sT_dF.pos : {943.39672851563, 601.5}
    sT_dF.mass : 1.6000000238419
    sT_dF.lastPos : {943.24060058594, 601.97082519531}
    sT_dF.totalMoved : {-5.4498901367188, 28.54443359375}
    
    
    sT_param.baseGravity : 80
    sT_param.diffDivisor : 30
    sT_param.damageThreshold : 1.5
    sT_param.velocityThreshold : {1024, 40}
    sT_param.mode : gravMod
    sT_param.baseVelocity : {69.8, 69.8}
    sT_param.damageFactor : 3
    sT_param.travelThreshold : {1024, 14}
    
    )------End_of_damageRequest------
    
    That's me actually calling this function more than once for different tables, but I can add previous results into new results.



    All this - not to mention your log file itself - would probably be easier to read with the custom language setting I used and just attached (for importing into Notepad++). I had to put it in a 7z file so the forum would allow it to be attached but the actual file is XML.

    Anyhow where you are at is wanting to add a lot of log dumping code into your current script. You can comment it out later. Because the question that should follow "it isn't doing what I expected" should be "well what IS it doing". So dump the arguments you're sending to the function that is crashing. Do your dump right before the crash point. And where you might not be sure how far things are getting, debug code can tell you that too. If it is supposed to drop a particular message, and that message isn't in your log... that code never ran.
     

    Attached Files:

    Inf_Wolf14 and Cyel like this.

Share This Page