dragged items - scrolling with mousewheel [solved]

  • #1, by esmeraldaMonday, 28. January 2019, 10:35 5 years ago
    Hi,
    I wanted to use SimonS' script for scrolling through your items with the mousewheel (changing the dragged item while hanging on the cursor) in a new project. But I'm getting an error : attempt to call a nil value (field 'getn')
    the line in question is:   local len = table.getn(items)
    It worked in an other project with a previous version of visionaire. So my guess is, that some command changed with the change of the Lua version. Could someone tell me what is wrong?

    -- author: SimonS
    -- Inventory scrolling by mouse wheel
    registerEventHandler("mouseEvent", "mouseEvtHandler")
    function mouseEvtHandler(evt)
        if evt == eEvtMouseWheelUp then
       wheelUp()
        end
        if evt == eEvtMouseWheelDown then
       wheelDown()
        end
    end
    function wheelUp ()
      local items = game:getLink(VGameCurrentCharacter):getLinks(VCharacterItems)
      local len = table.getn (items)
      local usedItem = game:getLink(VGameUsedItem)
      if len == 0 then
          game:setValue(VGameUsedItem,getObject("(-1,-1)"))
      else
          if usedItem:isEmpty() then
            game:setValue(VGameUsedItem,items[1])
          else
            for index = 0, len-1, 1 do
              if items[len-index]:getName() == usedItem:getName() then
                if len-index == len then
                  game:setValue(VGameUsedItem,getObject("(-1,-1)"))
                else
                  game:setValue(VGameUsedItem,items[len-index+1])
                end
                break
              end
            end
          end
      end
      game:setValue(VGameUsedItemPicked,true)
    end
    function wheelDown ()
      local character = getObject("Game.GameCurrentCharacter")
      local items = character:getLinks(VCharacterItems)
      local len = table.getn (items)
      local usedItem = game:getLink(VGameUsedItem)
      if len == 0 then
          game:setValue(VGameUsedItem,empty)
      else
        if usedItem:isEmpty() then
          game:setValue(VGameUsedItem,items[len])
        else
          for i = 1, len, 1 do
            if items:getName() == usedItem:getName() then
              if i == 1 then
                game:setValue(VGameUsedItem,getObject("(-1,-1)"))
              else
                game:setValue(VGameUsedItem,items[i-1])
              end
              break
            end
          end
        end
      end
      game:setValue(VGameUsedItemPicked,true)
    end





    Edit: solved
    local len = table.getn(items)  needs to be replaced by  local len = #items

    Thank you SimonS!

    Key Killer

    513 Posts