会话变量
设置、读取和刷新当前菜单中的状态。
点击计数
在菜单顶层初始化:
# 在菜单顶层初始化;返回 true 允许打开
events:
pre_open: 'ctx set clicks to 0 true'在面板 icons 中添加按钮:
# 放在 icons 下
A:
material: PAPER
name: '&f点击次数: {{&clicks}}'
action: 'ctx inc clicks by 1 icon update'每次打开从 0 开始,点击后增加 1 并刷新显示。
常用语句
| 语句 | 作用 |
|---|---|
ctx set key to value | 设置值 |
ctx get key | 读取值 |
ctx has key | 值是否存在且非空 |
ctx without key | 值不存在或为空 |
ctx del key | 删除值 |
ctx inc key by 1 | 数值加 1 |
ctx dec key by 1 | 数值减 1 |
ctx update | 更新当前会话读取的持久数据 |
context 与 ctx 等价。在文字中使用 {{&key}} 读取值。has 检查是否有值,0 和 false 都属于已存在的值。
更新图标
变量修改后,使用 icon update 更新当前图标文字,或 icons update 更新现有图标显示。子状态变化用 icon refresh,或 icons relocate 配合 icons update。icons refresh 会重建生成器列表并回到第一页,固定导航单独刷新。
action: 'ctx set status to ready icon refresh'刷新方式见图标。
切换与保存
| 使用方式 | 状态保留范围 |
|---|---|
| 普通 ctx 变量 | 当前菜单会话 |
menu open settings | 打开新会话 |
menu switch settings / menu open_ctx settings | 将当前状态传给新菜单 |
| meta | 玩家临时数据,重启后不保留 |
带 player@ / global@ 前缀的变量 | 持久数据 |
个人设置与全局变量见持久数据。
最后更新于