Skip to reading
Save Games & Inventory

A complete, guarded combination script

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

Create a GDScript record named Lubricate the gear with ID oil_gear. Apply this complete source:

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    if not HasInventory("oil"):
        return false
    if not HasInventory("brass_gear"):
        return false
    await RemoveInventory({"itemId": "oil", "count": 1})
    await RemoveInventory({"itemId": "brass_gear", "count": 1})
    await AddInventory({"itemId": "lubricated_gear", "count": 1})
    await SetVariable({
        "name": "inventory_feedback",
        "value": "The gear is now lubricated."
    })
    return true

The checks prevent a free reward if the recipe is called without its ingredients. The removals consume one oil and the old gear. The add gives the replacement item. A second call fails once the old gear has gone.

The result must already have a valid inventory definition, and the active player must be allowed to carry it. If the result is stackable, allow enough capacity for it before consuming ingredients in a more complicated recipe.

Use explicit Remove Inventory actions on the successful path. Although Consume On Use is exposed in the item settings, do not rely on it as automatic recipe consumption in 0.86.3.4.

Page 26 of 96Permalink
Go to page