# Defold Token - Countable Items Container

**URL:** <https://forum.defold.com/t/defold-token-countable-items-container/82407>\
**Category:** The Defoldmine\
**Created:** [February 21, 2026, 10:01am UTC](https://forum.defold.com/t/defold-token-countable-items-container/82407 "2026-02-21T10:01:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Insality](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/insality/32/39737_2.png) [@Insality](https://forum.defold.com/u/Insality)\
**Post date:** [February 21, 2026, 10:01am UTC](https://forum.defold.com/t/defold-token-countable-items-container/82407/1 "2026-02-21T10:01:19Z")

</div>

![logo](https://forum-defold-uploads.b-cdn.net/original/3X/f/7/f7599cebcf03827931fa5eeb3c46f913341497f3.jpeg)

# Token

**Token** - library designed for the [Defold](https://defold.com/) game engine to manage countable items such as money, lives, and other numeric values. This library provides a robust and flexible system for handling various token-related operations, including creation, management, and restoration of token values.

## Features

- **Token Management** - Create, delete, and manage tokens within containers.
- **Container Management** - Create, delete, and manage token containers.
- **Visual Management** - Control the displayed amount separately from the actual value for smooth UI animations.
- **Callbacks** - Customizable callbacks for token changes.
- **Token Groups** - Support for grouped token operations.
- **Token Restoration** - Configurable restoration mechanics for tokens.
- **Infinity Tokens** - Manage tokens with infinite time usage.

## Setup

See the [**Defold Token**](https://github.com/Insality/defold-token) repository on Github

- [Setup](https://github.com/Insality/defold-token?tab=readme-ov-file#setup)
- [API Reference](https://github.com/Insality/defold-token/?tab=readme-ov-file#quick-api-reference)
- [Use Cases](https://github.com/Insality/defold-token/blob/main/USE_CASES.md)

## Basic Usage

In Token library, you create a container which contains tokens.

```lua
local token = require("token.token")

token.init({
	["money"] = { default = 100, min = 0, max = 10000 },
	["exp"] = {},
	["level"] = { default = 1, min = 1, max = 100 },
})

local state = token.get_state() -- get the current state for save/load
token.set_state(state) -- set the state for save/load

token.container("wallet"):add("exp", 100) -- Will be 100, due the default value is 0
token.container("wallet"):add("level", 1) -- Will be 2, due the default value is 1
token.container("wallet"):pay("money", 100) -- Will be 0, due the default value is 100
token.container("wallet"):add("gems", 20) -- Token configs is not required to operate with tokens

-- Configs is not required to operate with tokens
token.container("skill"):add("damage", 100) -- Return token instance
token.container("skill"):get("damage") -- Return 100
token.container("skill"):set("crit_chance", 0.1) -- Set crit chance to 10%

```

Read [Use Cases](https://github.com/Insality/defold-token/blob/main/USE_CASES.md) for more examples.

## ❤ Support project ❤

Your donation helps me stay engaged in creating valuable projects for **Defold**. If you appreciate what I’m doing, please consider supporting me!

[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)

---

<div class="post-metadata">

**Author:** ![Insality](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/insality/32/39737_2.png) [@Insality](https://forum.defold.com/u/Insality)\
**Post date:** [February 21, 2026, 10:01am UTC](https://forum.defold.com/t/defold-token-countable-items-container/82407/2 "2026-02-21T10:01:42Z")

</div>

There is several Debug Panels Druid’s Widgets in the [Asset Store](https://github.com/Insality/asset-store). One of them is **Token Debug Panel** which allows you to see the current state of the tokens and containers and make some actions with them.

Live example: [Asset Store 1.0](https://insality.github.io/asset-store/examples/widget/Insality:debug_page_token@1/index.html)  
Source code: [asset-store/widget/Insality/debug\_page\_token/example/example\_debug\_page\_token.gui\_script at main · Insality/asset-store · GitHub](https://github.com/Insality/asset-store/blob/main/widget/Insality/debug_page_token/example/example_debug_page_token.gui_script)

This debug panel built with **Druid** Properties Panel Widget. You can easily extend it to your own needs by adding new properties or modifying the existing ones.

---

<div class="post-metadata">

**Author:** ![JuLongZhiLu](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/julongzhilu/32/42720_2.png) [@JuLongZhiLu](https://forum.defold.com/u/JuLongZhiLu)\
**Post date:** [February 21, 2026, 10:40am UTC](https://forum.defold.com/t/defold-token-countable-items-container/82407/3 "2026-02-21T10:40:16Z")

</div>

Thank you
