• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient Lua Error

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
58
Somebody can explain me this error ?? I wanna learn what I'm doing wrong..

Terminal OTC
Lua:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:117: attempt to index local 'itemWidget' (a nil value)
stack traceback:
    [C]: in function '__index'
    /game_inventory/inventory.lua:117: in function 'onInventoryChange'
    /game_inventory/inventory.lua:77: in function 'refresh'
    /game_inventory/inventory.lua:47: in function 'init'
    /game_inventory/inventory.otmod:8:[@onLoad]:1: in main chunk
    [C]: in function 'reloadModules'
    /client_modulemanager/modulemanager.lua:149: in function 'reloadAllModules'
    /client_modulemanager/modulemanager.otui:75: [@onClick]:2: in function </client_modulemanager/modulemanager.otui:75: [@onClick]:1>

Inventory.lua
Lua:
InventorySlotStyles = {
  [InventorySlotHead] = "HeadSlot",
  [InventorySlotNeck] = "NeckSlot",
  [InventorySlotBack] = "BackSlot",
  [InventorySlotBody] = "BodySlot",
  [InventorySlotRight] = "RightSlot",
  [InventorySlotLeft] = "LeftSlot",
  [InventorySlotLeg] = "LegSlot",
  [InventorySlotFeet] = "FeetSlot",
  [InventorySlotFinger] = "FingerSlot",
  [InventorySlotAmmo] = "AmmoSlot",
  [InventorySlotGauntlets] = "GauntletsSlot",
  [InventorySlotBracers] = "BracersSlot",
  [InventorySlotRing2] = "Ring2Slot"
}

inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil
purseButton = nil

function init()
  connect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  connect(g_game, { onGameStart = refresh })

  g_keyboard.bindKeyDown('Ctrl+I', toggle)

  inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
  inventoryButton:setOn(true)

  inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
  inventoryWindow:disableResize()
  inventoryPanel = inventoryWindow:getChildById('contentsPanel')

  purseButton = inventoryPanel:getChildById('purseButton')
  local function purseFunction()
    local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
    if purse then
      g_game.use(purse)
    end
  end
  purseButton.onClick = purseFunction

  refresh()
  inventoryWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  disconnect(g_game, { onGameStart = refresh })

  g_keyboard.unbindKeyDown('Ctrl+I')

  inventoryWindow:destroy()
  inventoryButton:destroy()
end

function toggleAdventurerStyle(hasBlessing)
  for slot = InventorySlotFirst, InventorySlotLast do
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
      itemWidget:setOn(hasBlessing)
    end
  end
end

function refresh()
  local player = g_game.getLocalPlayer()
  for i = InventorySlotFirst, InventorySlotPurse do
    if g_game.isOnline() then
      onInventoryChange(player, i, player:getInventoryItem(i))
    else
      onInventoryChange(player, i, nil)
    end
    toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
  end

  purseButton:setVisible(g_game.getFeature(GamePurseSlot))
end

function toggle()
  if inventoryButton:isOn() then
    inventoryWindow:close()
    inventoryButton:setOn(false)
  else
    inventoryWindow:open()
    inventoryButton:setOn(true)
  end
end

function onMiniWindowClose()
  inventoryButton:setOn(false)
end

-- hooked events
function onInventoryChange(player, slot, item, oldItem)
  if slot > InventorySlotPurse then return end

  if slot == InventorySlotPurse then
    if g_game.getFeature(GamePurseSlot) then
      purseButton:setEnabled(item and true or false)
    end
    return
  end

  local itemWidget = inventoryPanel:getChildById('slot' .. slot)
  if item then
    itemWidget:setStyle('InventoryItem')
    itemWidget:setItem(item)
  else
    itemWidget:setStyle(InventorySlotStyles[slot])
    itemWidget:setItem(nil)
  end
end

function onBlessingsChange(player, blessings, oldBlessings)
  local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
  if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
    toggleAdventurerStyle(hasAdventurerBlessing)
  end
end
 
Somebody can explain me this error ?? I wanna learn what I'm doing wrong..

Terminal OTC
Lua:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:117: attempt to index local 'itemWidget' (a nil value)
stack traceback:
    [C]: in function '__index'
    /game_inventory/inventory.lua:117: in function 'onInventoryChange'
    /game_inventory/inventory.lua:77: in function 'refresh'
    /game_inventory/inventory.lua:47: in function 'init'
    /game_inventory/inventory.otmod:8:[@onLoad]:1: in main chunk
    [C]: in function 'reloadModules'
    /client_modulemanager/modulemanager.lua:149: in function 'reloadAllModules'
    /client_modulemanager/modulemanager.otui:75: [@onClick]:2: in function </client_modulemanager/modulemanager.otui:75: [@onClick]:1>

Inventory.lua
Lua:
InventorySlotStyles = {
  [InventorySlotHead] = "HeadSlot",
  [InventorySlotNeck] = "NeckSlot",
  [InventorySlotBack] = "BackSlot",
  [InventorySlotBody] = "BodySlot",
  [InventorySlotRight] = "RightSlot",
  [InventorySlotLeft] = "LeftSlot",
  [InventorySlotLeg] = "LegSlot",
  [InventorySlotFeet] = "FeetSlot",
  [InventorySlotFinger] = "FingerSlot",
  [InventorySlotAmmo] = "AmmoSlot",
  [InventorySlotGauntlets] = "GauntletsSlot",
  [InventorySlotBracers] = "BracersSlot",
  [InventorySlotRing2] = "Ring2Slot"
}

inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil
purseButton = nil

function init()
  connect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  connect(g_game, { onGameStart = refresh })

  g_keyboard.bindKeyDown('Ctrl+I', toggle)

  inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
  inventoryButton:setOn(true)

  inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
  inventoryWindow:disableResize()
  inventoryPanel = inventoryWindow:getChildById('contentsPanel')

  purseButton = inventoryPanel:getChildById('purseButton')
  local function purseFunction()
    local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
    if purse then
      g_game.use(purse)
    end
  end
  purseButton.onClick = purseFunction

  refresh()
  inventoryWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  disconnect(g_game, { onGameStart = refresh })

  g_keyboard.unbindKeyDown('Ctrl+I')

  inventoryWindow:destroy()
  inventoryButton:destroy()
end

function toggleAdventurerStyle(hasBlessing)
  for slot = InventorySlotFirst, InventorySlotLast do
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
      itemWidget:setOn(hasBlessing)
    end
  end
end

function refresh()
  local player = g_game.getLocalPlayer()
  for i = InventorySlotFirst, InventorySlotPurse do
    if g_game.isOnline() then
      onInventoryChange(player, i, player:getInventoryItem(i))
    else
      onInventoryChange(player, i, nil)
    end
    toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
  end

  purseButton:setVisible(g_game.getFeature(GamePurseSlot))
end

function toggle()
  if inventoryButton:isOn() then
    inventoryWindow:close()
    inventoryButton:setOn(false)
  else
    inventoryWindow:open()
    inventoryButton:setOn(true)
  end
end

function onMiniWindowClose()
  inventoryButton:setOn(false)
end

-- hooked events
function onInventoryChange(player, slot, item, oldItem)
  if slot > InventorySlotPurse then return end

  if slot == InventorySlotPurse then
    if g_game.getFeature(GamePurseSlot) then
      purseButton:setEnabled(item and true or false)
    end
    return
  end

  local itemWidget = inventoryPanel:getChildById('slot' .. slot)
  if item then
    itemWidget:setStyle('InventoryItem')
    itemWidget:setItem(item)
  else
    itemWidget:setStyle(InventorySlotStyles[slot])
    itemWidget:setItem(nil)
  end
end

function onBlessingsChange(player, blessings, oldBlessings)
  local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
  if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
    toggleAdventurerStyle(hasAdventurerBlessing)
  end
end
Change this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end

    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end

    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if item then
        itemWidget:setStyle('InventoryItem')
        itemWidget:setItem(item)
    else
        itemWidget:setStyle(InventorySlotStyles[slot])
        itemWidget:setItem(nil)
    end
end
to this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end

    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end

    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
        if item then
            itemWidget:setStyle('InventoryItem')
            itemWidget:setItem(item)
        else
            itemWidget:setStyle(InventorySlotStyles[slot])
            itemWidget:setItem(nil)
        end
    end
end
 
Change this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end

    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end

    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if item then
        itemWidget:setStyle('InventoryItem')
        itemWidget:setItem(item)
    else
        itemWidget:setStyle(InventorySlotStyles[slot])
        itemWidget:setItem(nil)
    end
end
to this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end

    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end

    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
        if item then
            itemWidget:setStyle('InventoryItem')
            itemWidget:setItem(item)
        else
            itemWidget:setStyle(InventorySlotStyles[slot])
            itemWidget:setItem(nil)
        end
    end
end

This don't work :(:(

Get this error:
Code:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function 'onInventoryChange'
    /game_inventory/inventory.lua:69: in function 'refresh'
    /game_inventory/inventory.lua:37: in function 'init'
    /game_inventory/inventory.otmod:8:[@onLoad]:1: in main chunk
    [C]: in function 'ensureModuleLoaded'
    /init.lua:46: in main chunk
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function 'onInventoryChange'
    /game_inventory/inventory.lua:67: in function </game_inventory/inventory.lua:63>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
 
This don't work :(:(

Get this error:
Code:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function 'onInventoryChange'
    /game_inventory/inventory.lua:69: in function 'refresh'
    /game_inventory/inventory.lua:37: in function 'init'
    /game_inventory/inventory.otmod:8:[@onLoad]:1: in main chunk
    [C]: in function 'ensureModuleLoaded'
    /init.lua:46: in main chunk
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function 'onInventoryChange'
    /game_inventory/inventory.lua:67: in function </game_inventory/inventory.lua:63>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
ERROR: protected lua call failed: LUA ERROR:
/game_inventory/inventory.lua:92: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /game_inventory/inventory.lua:92: in function </game_inventory/inventory.lua:91>
It does work this is just a new error. Post the code with the changes you made or just post line 92
Code:
/game_inventory/inventory.lua:92: attempt to compare nil with number
 
This is the code.

@Edit: I removed the Purse from my server....

Lua:
InventorySlotStyles = {
  [InventorySlotHead] = "HeadSlot",
  [InventorySlotNeck] = "NeckSlot",
  [InventorySlotBack] = "BackSlot",
  [InventorySlotBody] = "BodySlot",
  [InventorySlotRight] = "RightSlot",
  [InventorySlotLeft] = "LeftSlot",
  [InventorySlotLeg] = "LegSlot",
  [InventorySlotFeet] = "FeetSlot",
  [InventorySlotFinger] = "FingerSlot",
  [InventorySlotAmmo] = "AmmoSlot",
  [InventorySlotGauntlets] = "GauntletsSlot",
  [InventorySlotBracers] = "BracersSlot",
  [InventorySlotRing2] = "Ring2Slot"
}

inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil

function init()
  connect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  connect(g_game, { onGameStart = refresh })

  g_keyboard.bindKeyDown('Ctrl+I', toggle)

  inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
  inventoryButton:setOn(true)

  inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
  inventoryWindow:disableResize()
  inventoryPanel = inventoryWindow:getChildById('contentsPanel')

  refresh()
  inventoryWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, {
    onInventoryChange = onInventoryChange,
    onBlessingsChange = onBlessingsChange
  })
  disconnect(g_game, { onGameStart = refresh })

  g_keyboard.unbindKeyDown('Ctrl+I')

  inventoryWindow:destroy()
  inventoryButton:destroy()
end

function toggleAdventurerStyle(hasBlessing)
  for slot = InventorySlotFirst, InventorySlotLast do
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
      itemWidget:setOn(hasBlessing)
    end
  end
end

function refresh()
  local player = g_game.getLocalPlayer()
  for i = InventorySlotFirst, InventorySlotLast do
    if g_game.isOnline() then
      onInventoryChange(player, i, player:getInventoryItem(i))
    else
      onInventoryChange(player, i, nil)
    end
    toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
  end

end

function toggle()
  if inventoryButton:isOn() then
    inventoryWindow:close()
    inventoryButton:setOn(false)
  else
    inventoryWindow:open()
    inventoryButton:setOn(true)
  end
end

function onMiniWindowClose()
  inventoryButton:setOn(false)
end

-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end
    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
        if item then
            itemWidget:setStyle('InventoryItem')
            itemWidget:setItem(item)
        else
            itemWidget:setStyle(InventorySlotStyles[slot])
            itemWidget:setItem(nil)
        end
    end
end

function onBlessingsChange(player, blessings, oldBlessings)
  local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
  if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
    toggleAdventurerStyle(hasAdventurerBlessing)
  end
end
 
change this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then return end
    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
        if item then
            itemWidget:setStyle('InventoryItem')
            itemWidget:setItem(item)
        else
            itemWidget:setStyle(InventorySlotStyles[slot])
            itemWidget:setItem(nil)
        end
    end
end
to this
Lua:
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if not slot or not InventorySlotPurse then return end
    if slot > InventorySlotPurse then return end
    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end
    local itemWidget = inventoryPanel:getChildById('slot' .. slot)
    if itemWidget then
        if item then
            itemWidget:setStyle('InventoryItem')
            itemWidget:setItem(item)
        else
            itemWidget:setStyle(InventorySlotStyles[slot])
            itemWidget:setItem(nil)
        end
    end
end
 
Nice @Digital !! Now I don't have any error, but it don't show my equipments there

@Edit: Bro, Now it's working..

I deleted this part. Thanks for the attention Bro!!

Lua:
    if not slot or not InventorySlotPurse then return end
    if slot > InventorySlotPurse then return end
    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end
 
Last edited:
Back
Top