Inventory Tutorial (cliff notes) - AutoSave Updated

Inventory Tutorial (cliff notes)

Official Tutorial: Using the Inventory Package

Install

Inventory Package

  • search for inventory
  • check Crayta Packages
  • click Install

Configure

User and Player template

  • drag and drop User Inventory template onto User template
  • drag and drop Player Inventory View template onto Player template
  • (optional) rename to … InventoryInventoryView
User Template Player Template

Inventory Size

  • Max Size
  • adjust for more slots
inventoryScript

Item Templates

Template creation

  • drop a mesh on world
  • select mesh in world tree
  • create Template
select mesh create Template

inventoryItemSpecScript

  • required for all inventory items
  • select Template
    • add / configure script
    • set carry to none for no grip (double click on left)
select Template inventoryItemSpecScript

Inventory Defaults

  • reqs: template with inventoryItemSpecScript
  • add the script for each default item
inventoryDefaultScript

Item Template

pickupSpawnerScript

  • add to template
  • min/max respawnTime property to 5 seconds
  • click Show on Init
  • Use On Collision - pickup when player makes contact with mesh
pickupSpawnerScript

Saving / Loading Items

Install AutoSave

AutoSave Package

  • search for save
  • check Crayta Packages
  • click Install

User Template

  • add script folder under User Template called AutoSave
  • add scripts
    • autoSaveScript
    • inventorySaveScript
  • configure
    • On Load = AutoSave / inventorySaveScript / OnLoad
    • On Save = AutoSave / inventorySaveScript / OnSave
  • (optional)
    • On Unload = AutoSave / inventorySaveScript / Unload
    • this will not show in preview
    • if 2nd user joins and logout, it will save their inventory in preview
AutoSave Script Folder AutoSave On Unload

Adventure Script

  • needed to kick off auto save
  • create new script called adventureScript
  • create locator in world named adventure
  • added script to locator named adventure

adventureScript

local AdventureScript = {}

AdventureScript.Properties = {
}

-- simple OnUserLogin callback, sent by the game
-- when a user logs in. This one calls Load on autoSaveScript
-- and then spawns a player for the user when everything loaded...
function AdventureScript:OnUserLogin(user)
    
    user.autoSaveScript:Load(
        function()
            Print("Adventure: Spawning")
            user:SpawnPlayer(nil)
        end    
    )
    
end

-- when a user leaves make sure they are saved...
function AdventureScript:OnUserLogout(user)
    user.autoSaveScript:Unload()
end

return AdventureScript

AutoSave should now work

2 Likes