Armor Inventory Problem

Place to get help with not working mods / modding interface.
Post Reply
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Armor Inventory Problem

Post by kiba »

Code: Select all

function getArmor(index)
  local armor = game.players[index].get_inventory(defines.inventory.player_armor)[1]
  return armor
end

function armorCheck(index)
  local armor = getArmor(index)
  if armor.grid ~= nil then
    return true
  end
  return false
end

script.on_event(defines.events.on_player_armor_inventory_changed, function(event)
  local index = event.player_index
  if armorCheck(index) then
    local armor = getArmor(index)
    local equipment = armor.grid.equipment
    for i, e in ipairs(equipment) do
      if e.name == "hoverboard" then
        activateEquipment(index)
      end
    end
  else
    deactivateEquipment(index)
  end
end)
Error:

Code: Select all

Error while running event on_player_armor_inventory_changed (ID 35)
LuaItemStack API call when LuaItemStack was invalid.
stack traceback:
	__MagneticFloor__/src/armor.lua:8: in function 'armorCheck'
	__MagneticFloor__/src/armor.lua:16: in function <__MagneticFloor__/src/armor.lua:14>
I don't understand what's going on when I removed a power armor item. I believe I got a valid ItemStack, but then it doesn't let me do anything or tell me if it's empty.

If I do anything like ItemStack.count or ItemStack.name, it gives me the same error.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Armor Inventory Problem

Post by Rseding91 »

If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Armor Inventory Problem

Post by Rseding91 »

Also, get_inventory(defines.inventory.player_armor) can return nil if the player has no character so you'll need to check for nil on that first.
If you want to get ahold of me I'm almost always on Discord.

kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Armor Inventory Problem

Post by kiba »

Thanks. I spent about hour or so trying to fix it before giving up and asking for help. Wish I have done earlier, but I have a tendency to try to try everything myself first before asking for help.

Post Reply

Return to “Modding help”