Getting nil from the table all the time dont know if i need to return it in this situation

Here is the script where its returning nil

local inputMap = {
    mouseType = "MouseButton2";
    keyType = nil;
    execFunction = function(Toggle)
        weapon:aim(Toggle)
    end;
    contextName = "Aim";
}

for i,v in pairs(inputMap) do

    local function Bind(toggle, event)
        local function toggled()
            weapon.keyPressStates[v.contextName] = toggle
            v.execFunction(toggle)
        end
        Inputs[event](v.mouseType, v.keyType, toggled, v.contextName..tostring(toggle))
    end

    weapon.keyPressStatesp[v.contextName] = false

    Bind(true, "BindOnBegan")
    Bind(false, "BindOnEnded")

end

When im tyring to get it in the for loop it wont return the value of anything in it because it returns nil

You technically have a dictionary. If you want to use this, add a second pair of braces around your input map:

local inputMap = {
  {
      mouseType = "MouseButton2";
      keyType = nil;
      execFunction = function(Toggle)
          weapon:aim(Toggle)
      end;
      contextName = "Aim";
  },
  {
    -- Other mapping
  },
  {
    -- Other mapping
  },
  --...
}

and change pairs to ipairs

1 Like

I got it working with the dictionary thanks for helping i never knew the different between each one