thomas4846

How to index a nil value? (solved)

Recommended Posts

thomas4846    740

whenever i try to run the code it will work till the actually action happens saying "attempt to index combat (nil value)"

it happens whenever the attack happens and this only actually accrues when caves are turned on; any help is appreciated 

local touch = 
        State{
        name = "touch",
        tags = { "doing", "busy", "prechanneling","touch" },

        onenter = function(inst)
            inst.AnimState:PlayAnimation("channel_pre")
            inst.AnimState:PushAnimation("channel_loop", true)
            inst.sg:SetTimeout(0.7)
        end,


        timeline =
        {
            TimeEvent(7 * FRAMES, function(inst)
                inst.components.locomotor:Stop()
                inst.sg:RemoveStateTag("busy")
            end),
        },
        ontimeout = function(inst)
            inst:PerformBufferedAction() ---------> this is when the error happens
            inst.AnimState:PlayAnimation("channel_pst")
            inst.sg:GoToState("idle", true)
        end,
    }

AddStategraphState("wilson_client", touch)
Spoiler

[00:32:47]: [string "scripts/actions.lua"]:962: attempt to index field 'combat' (a nil value)
LUA ERROR stack traceback:
scripts/actions.lua:962 in (field) fn (Lua) <945-964>
   act = Attack 103032 - rook (valid:true)
scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
   self (valid:true) =
      onsuccess = table: 0x2a423130
      options = table: 0xaf89760
      action = table: 0xc4a9b40
      doer = 101714 - wortox (valid:true)
      target = 103032 - rook (valid:true)
      doerownsobject = false
      preview_cb = function - scripts/components/playercontroller.lua:1318
      onfail = table: 0xaf89730
scripts/entityscript.lua:1313 in (method) PerformBufferedAction (Lua) <1305-1323>
   self (valid:true) =
      DynamicShadow = DynamicShadow (0x13971f80)
      inlimbo = false
      GetMoistureRateScale = function - scripts/prefabs/player_common.lua:146
      ghostenabled = true
      EnableMovementPrediction = function - scripts/prefabs/player_common.lua:521
      worldstatewatching = table: 0x27422d80
      playercolour = table: 0x246de610
      IsOverheating = function - scripts/prefabs/player_common.lua:116
      Light = Light (0x1396f580)
      Network = Network (0x247ebcc0)
      OnRemoveEntity = function - scripts/prefabs/player_common.lua:664
      GetMoisture = function - scripts/prefabs/player_common.lua:126
      pendingtasks = table: 0x113bfe40
      LightWatcher = LightWatcher (0x1c79ee10)
      sg = sg="wilson_client", state="touch", time=0.70, tags = "doing,touch,prechanneling,"
      spawntime = 19.000000990927
      replica = table: 0x12106ac0
      SetGhostMode = function - scripts/prefabs/player_common.lua:577
      ondetachclassified = function - scripts/prefabs/player_common.lua:655
      HUD = HUD
      player_classified = 102854 - player_classified (valid:true)
      Transform = Transform (0x117a86b0)
      inherentactions = table: 0x2b667850
      name = Thomas4843
      actionreplica = table: 0x12107f40
      event_listening = table: 0x121073a0
      prefab = wortox
      actioncomponents = table: 0x2b667790
      userid = KU_-SxQ8SC_
      lower_components_shadow = table: 0x12108b40
      GetMaxMoisture = function - scripts/prefabs/player_common.lua:136
      updatecomponents = table: 0xbc7e360
      entity = Entity (0x1d1e1b10)
      CanUseTouchStone = function - scripts/prefabs/player_common.lua:86
      IsCarefulWalking = function - scripts/prefabs/player_common.lua:160
      IsActionsVisible = function - scripts/prefabs/player_common.lua:984
      AttachClassified = function - scripts/prefabs/player_common.lua:653
      ShakeCamera = function - scripts/prefabs/player_common.lua:1038
      persists = true
      GUID = 101714
      MiniMapEntity = MiniMapEntity (0x128c0ef0)
      SoundEmitter = SoundEmitter (0x18523a60)
      GetSandstormLevel = function - scripts/prefabs/player_common.lua:156
      IsFreezing = function - scripts/prefabs/player_common.lua:106
      AnimState = AnimState (0x1c79d7c0)
      Physics = Physics (0x1ef112f0)
      event_listeners = table: 0x162eae60
      DetachClassified = function - scripts/prefabs/player_common.lua:659
      bufferedaction = Attack 103032 - rook (valid:true)
      components = table: 0x12108f90
      GetTemperature = function - scripts/prefabs/player_common.lua:96
../mods/11 wortox mod/modmain.lua:103 in (field) ontimeout (Lua) <102-106>
   inst = 101714 - wortox (valid:true)
scripts/stategraph.lua:554 in (method) UpdateState (Lua) <540-584>
   self =
      tags = table: 0x2ba34910
      mem = table: 0x250798a0
      statemem = table: 0x2ba348e0
      currentstate = table: 0xb51b7d0
      timeinstate = 0.70000003650784
      sg = Stategraph : wilson_client
      inst = 101714 - wortox (valid:true)
      bufferedevents = table: 0x1f99bf40
      lastupdatetime = 24.96666796878
      laststate = table: 0x1dfc3660
      statestarttime = 24.266667932272
   dt = 0.46666669100523
   startstate = table: 0xb51b7d0
scripts/stategraph.lua:611 in (method) Update (Lua) <603-631>
   self =
      tags = table: 0x2ba34910
      mem = table: 0x250798a0

Edited by thomas4846

Share this post


Link to post
Share on other sites
Mr. Tiddles    1,020
On 1/1/2020 at 4:14 AM, thomas4846 said:

[00:32:47]: [string "scripts/actions.lua"]:962: attempt to index field 'combat' (a nil value)

The issue is actually in the combat action.

Actions.lua:

ACTIONS.ATTACK.fn = function(act)
    if act.doer.sg ~= nil then
        if act.doer.sg:HasStateTag("propattack") then
            --don't do a real attack with prop weapons
            return true
        elseif act.doer.sg:HasStateTag("thrusting") then
            local weapon = act.doer.components.combat:GetWeapon()
            return weapon ~= nil
                and weapon.components.multithruster ~= nil
                and weapon.components.multithruster:StartThrusting(act.doer)
        elseif act.doer.sg:HasStateTag("helmsplitting") then
            local weapon = act.doer.components.combat:GetWeapon()
            return weapon ~= nil
                and weapon.components.helmsplitter ~= nil
                and weapon.components.helmsplitter:StartHelmSplitting(act.doer)
        end
    end
    act.doer.components.combat:DoAttack(act.target)  <LINE 962
    return true
end

May I see the rest of your mod to see what's up?

Share this post


Link to post
Share on other sites
thomas4846    740

(just in case anyone wants to know how it was solved it had to be previewbufferedaction cus it's client and i guess client doesn't have combat hence it being nil (thnx Hornet <3)

  • Thanks 1

Share this post


Link to post
Share on other sites
Void Heart    1
On 1/5/2020 at 1:29 AM, thomas4846 said:

(just in case anyone wants to know how it was solved it had to be previewbufferedaction cus it's client and i guess client doesn't have combat hence it being nil (thnx Hornet <3)

Certainly "Yes". I've had the same "index field '*' (a nil value)" problem, too. 

My thought in a word: Some "components" can't accept some certain functions that hold some certain "local variables". (This explains the part of the problem. I didn't say it's this answer that is the whole explanation of the problem.)

  • Like 1

Share this post


Link to post
Share on other sites