set_pinv issue

Discussion in 'CommandHelper' started by MrSnowGlobe, Apr 11, 2018.

  1. MrSnowGlobe

    MrSnowGlobe New Member

    Hello!

    I have created a basic method of having per-world player inventories, see script below:
    PHP:
    #Save inventories on inventory close
    bind(inventory_close, null, null, @event,
        if(pget_virtualchest() != null){die()}
        @uuid = puuid(player(), true)
        @world = pworld()
        @inv = pinv(player())
        store_value("shard."[email protected]world."."[email protected]uuid.".inv", array(@inv))
    )
    #Save inventories on item pickup
    bind(item_pickup, null, null, @event,
        @uuid = puuid(player(), true)
        @world = pworld()
        @inv = pinv(player())
        store_value("shard."[email protected]world."."[email protected]uuid.".inv", array(@inv))
    )

    #Restore player inventory of world they are going too
    bind(world_changed, null, null, @event,
        @uuid = puuid(player(), true)
        @world = @event[to]
        @inv = get_value("shard."[email protected]world."."[email protected]uuid.".inv")
        set_pinv(player(), array(@inv))
    )
    The saving of an inventory appears to function correctly but when attempting to set the inventory, the following error is thrown: https://imgur.com/a/MdCOQ

    Here is the inv it is trying to set: https://pastebin.com/Dn2tqJr6

    Cheers,
    Snow
  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    That error means you passed an item array without the key "name" (or "type"). In this case it appears it's because you're wrapping the @inv array within another array. (twice, actually; once when you save, once when you load) It loops through the outer array and finds one array, which is an inv array, not an item array, thus without a "name" key.