ExamplesAdvanced

Items and Lore

Adapt examples for using inventory Items, charging Lore, transferring prizes, rewarding players, and changing the current Item.

These functions can affect real inventory or Lore. JOI shows the person using the creation what will happen and asks them to confirm any costs or Item use.

The Lore and inventory examples are complete Boop Code modules. They can also be placed inside Item actions. The current-Item examples are complete Item Code modules because Item::setQuality() and Item::mutate() must run from an Item action.

Charge for access

text {
  Lore::charge(15);
  show chip "Access granted";
  "@1 unlocks the special scene."
}

The 15 Lore goes to the Item or Boop creator. If the creator and participant 1 share a wallet, it is burned.

Transfer a prize between participants

text {
  let amount = 10;
  Lore::transfer(amount, 2);
  "@1 sends {amount} Lore to @2."
}

Participant 2 cannot be participant 1 or share the same wallet.

Verified reward

text {
  let requested = 25;
  let awarded = Lore::earn(requested);

  if awarded == requested {
    "@1 earned {awarded} Lore!"
  } else if awarded > 0 {
    "@1 earned {awarded} Lore before reaching today's limit."
  } else {
    "@1 completed the challenge, but has reached today's Lore reward limit."
  }
}

Lore::earn() requires a linked App verified by JOI. Always use its returned amount in the message because the actual reward may be smaller than requested.

Consume an inventory Item

var ticket: Item with {
  input: true,
  required: true,
};

text if ticket.blueprintId == "123456789012345678" {
    let used = Item::use(ticket);
    "@1 uses {used} ticket to enter."
  } else {
    "That Item is not a valid ticket."
}

Replace the example blueprint ID with the real copied ID.

The approval drawer names the Item and use count. Persistent Items return 0 rather than being consumed.

Upgrade the current Item

action upgrade -> "Upgrade Item" {
  let oldQuality = HOST.quality;
  let newQuality = Item::setQuality("ELITE");

  text "@1 upgrades {HOST.name} from {oldQuality} to {newQuality}.";
}

The user approves the positive mint-cost difference. Downgrades are free.

Transform the current Item

action transform -> "Transform Item" {
  Item::mutate("123456789012345678");
  text "@1 completes the transformation.";
}

The destination blueprint must be eligible, non-stackable, and from the same creator. Do not combine mutation and quality change in one action.