无编辑摘要 |
2020年11月11日 (三) 19:03的版本
Scopes are used in scripting to select entities in order to check for conditions or apply commands.
Uses
Scopes always have a bracketed block on the right side:
<scope_name> = { #Stuff to execute in the scope. }
But not all bracketed blocks are scopes: some are function blocks (option
, trigger
,...), operators (AND
), flow control statements (if
, limit
), or clause for complex conditions or commands (create_character
, ...).
There are several types of scopes accessible from script. These include, but are not limited to: character, title/holding, province, war, unit, religion, faith, culture.
Scopes can be nested, and are usually relative to the scope from which there are called, except for the ones that are global and can be called from "Any" scope.
In Jomini, Scopes can also be chained without nesting:
root.mother.father.killer = { #Things we want to do with the killer of the father of the mother of the root character. }
We can also directly compare scopes for equality:
trigger = { root.mother = scope:other_character.mother }
In CK3, the ability to save and recall scopes has been vastly simplified by the addition of the save_scope_as
command, which can save a given scope under a name, to be recalled later:
<scope> = { save_scope_as = <scope_name> } scope:<scope_name> = { #Stuff to execute in the scope. }
Saved scopes will stay saved within the current code chain, that is, they will remain accessible until every action/event/effect/etc that is run as a result of the current one has been evaluated to completion. They will only be accessible in the given code chain. For example, if there is an event chain that takes years to complete, a scope saved in the initial event will remain accessible until the concluding event, but will not be accessible to any other events that may occur during that time frame.
Triggers and effects in scopes are only evaluated and executed if the scope exists. This can be used with always = yes
to check for the existence of a scope in a trigger or for effects that you only want to execute if, for example, a character's religion has a religious head.
Note that the condition tooltips within any_
scopes are misleading and only show whether the conditions are satisfied for one specific, seemingly randomly-chosen thing contained within the scope, and thus may show that some conditions are false even when the scope itself evaluates to true. These are best overridden with a custom_tooltip
.
References
文档 | Effects • 触发器 • 修正 • 作用域 • 变量 • 数据类型 • 本地化 • 可定制的本地化 |
脚本 | AI • 剧本 • 角色 • 效果指令 • 内阁 • 文化 • 决议 • 宗族 • 事件 • 政体 • 历史 • 地产 • 生活方式 • 军队 • 宗教 • Story cycles • 头衔 • 特质 |
地图 | 地图 • 地形 |
图形 | 3D模型 • Exporters • 界面 • Coat of arms • Graphical assets • Fonts • Particles • Shaders • Unit models |
音频 | Music • Sound |
其他 | 控制台指令 • 校验码 • 模组结构 • Troubleshooting |