Forum rules - please read before posting.

Problem with inventorybox looping

Hey there,

I noticed a issue with the 'Supports looping?' feature of a InventoryBox.
Whenever this option is enabled and:

  • Inventory is empty, it results in:
    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.Collections.Generic.List1[T].get_Item (System.Int32 index) (at <7ec8e29954a6455daa48484a381ec418>:0)
    AC.MenuInventoryBox.GetItemList (System.Boolean doLimit) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:1842)
    AC.MenuInventoryBox.CopyInventoryBox (AC.MenuInventoryBox _element, System.Boolean ignoreUnityUI) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:243)
    AC.MenuInventoryBox.DuplicateSelf (System.Boolean fromEditor, System.Boolean ignoreUnityUI) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:163)
    AC.Menu.Copy (AC.Menu _menu, System.Boolean fromEditor, System.Boolean forceUIFields) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:381)
    AC.PlayerMenus.RebuildMenus (AC.MenuManager menuManager) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:156)
    AC.PlayerMenus.OnInitPersistentEngine () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:88)
    AC.StateHandler.Initialise (System.Boolean rebuildMenus) (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:121)
    AC.KickStarter.SetPersistentEngine () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:178)
    AC.KickStarter.Initialise () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1104)
    AC.MultiSceneChecker.Awake () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:45)
    `

  • Inventory has less items then available slots:
    It shows the current available items in the supposedly 'empty slots' instead of showing empty slots:
    https://ibb.co/SvRmKPJ

I have tested this in a minimal project, to make sure

Comments

  • Apologies for the hassle. I'll look into these - thanks for the details.

  • Recreated.

    To fix, open up AC's MenuInventoryBox script, and replace line 1837:

    if (canBeLooped)
    

    with:

    if (canBeLooped && newItemList.Count >= maxSlots)
    
  • Thanks! This works, another thing that popped up during testing after implementing this fix:

    When you only have -for example- 1 item in your inventory (anything less then max slots) and you do the following:

    • 'Shift Next': Game freezes for ~1 sec and then resumes.
    • 'Shift Previous': it crashes with the same error:
      ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
      Parameter name: index
      System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <7ec8e29954a6455daa48484a381ec418>:0)
      AC.MenuInventoryBox.Display (UnityEngine.GUIStyle _style, System.Int32 _slot, System.Single zoom, System.Boolean isActive) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:1120)
      AC.PlayerMenus.DrawMenu (AC.Menu menu, System.Int32 languageNumber) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:720)
      AC.PlayerMenus.DrawMenus () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:496)
      AC.StateHandler._OnGUI () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:463)
      AC.StateHandler.OnGUI () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:383)

    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

    I will also look at the code to see if i can figure something out. But you're faster for sure :smile:

  • Thanks, and apologies once more.

    In MenuElement, find the Shift function starting line 975, and insert the following at the top, line 977:

    if (canBeLooped && arraySize < maxSlots) return;
    

    There is also an issue with the Shift Left/Right buttons' Only show when visible? option, but this will be addressed in the next update.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.