Skip to reading
Lua Scripting

Inventory, quests and save slots

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

LESSON 18

Build an optional reward for finding the key. Keep the inventory item definition, the visible pickup and the quest in separate records.

Code example
local Script = {}
Code example
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")
end
Code example
return Script

Create 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#

Code example
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.

Page 36 of 133Permalink
Go to page