Inventory, quests and save slots
LESSON 18
Build an optional reward for finding the key. Keep the inventory item definition, the visible pickup and the quest in separate records.
local Script = {}function Script.run(context)
if IfVariable("key_claimed", true) then return false end
await(SetVariable({ name = "key_claimed", value = true }))
await(AddInventory({ itemId = "key", count = 1 }))
await(SetObjectVisible({ entityId = "key_pickup", visible = false }))
await(StartQuest({ questId = "archive_search" }))
await(AddScore({ amount = 5 }))
return InventoryCount("key")
endreturn ScriptCreate Boolean key_claimed with default false, inventory definition key, placed pickup key_pickup,
and quest archive_search. Attach the script to the pickup's Take interaction. Test on a fresh save.
Confirm one key and a five-point reward. Trigger it again and confirm that neither increases. If a
hidden hotspot can still receive input, also disable it with SetObjectEnabled.
To require possession at the door, check HasInventory("key") before unlocking. To consume a
single-use key, await RemoveInventory with itemId and count. Mark the door as unlocked
separately so using the key once keeps the door open.
Save a checkpoint · fragment#
await(SaveGameSlot({ slot = 2, saveName = "Before the archive" }))Load that checkpoint with await(LoadGameSlot({ slot = 2 })). Slot is numeric. Save names are
display text. Choose a disposable slot when practicing, since saving to an occupied slot can replace
a prior checkpoint.
