Set

*set 命令用于为变量分配新值,或将变量的值修改为其他内容。它既可用于临时变量(在故事脚本中使用 *temp 命令按需创建),也可用于永久变量(在 startup.txt 中使用 *create 命令定义)。对于这两种变量类型,*set 的使用方式并无实际区别。

设置数值变量|Setting Numeric Variables

假设我们有一个名为 "var" 的数值变量,我们为其分配的初始值为 10。

我们可以在故事脚本的任何地方,通过使用 *set 命令赋予其新值来改变其当前值:

*set var 20

这将直接覆盖 "var" 变量的当前值,将其从 10(或任意其他数值)更改为 20。

我们也可以仅修改其当前值,例如:

*set var + 15

这会将 "var" 变量的值增加 15,使其从 10 变为 25。

其他[[算术运算符]]同样适用。

我们也可以将一个数值型变量的值与另一个进行相加(或相减、相乘、相除),如下所示:

*set var + var1

设置字符串变量|Setting String Variables

变量并非总是数值类型。我们也可以为变量分配其他类型的值,例如字符串(文本):

*set var "Hello!"

Strings should always be enclosed within "quotation marks" as shown above. 字符串应始终如上所示,用“引号”括起来。

Note that there is no real limit to the number of alphanumeric characters (meaning letters and numbers, but also including common symbols such as exclamation and question marks) able to be included in a single string value, but very long text strings may be better handled as conditional text using the *if / *elseif / *else commands -- unless there is a very good reason for saving the data as string values. 请注意,单个字符串值中可以包含的字母数字字符(即字母和数字,但也包括常见符号,如感叹号和问号)数量实际上没有限制,但很长的文本字符串最好使用 *if / *elseif / *else 命令作为条件文本来处理——除非有非常充分的理由将数据保存为字符串值。

Note that you can also concatenate (combine) two or more strings, with the *set command. 请注意,您还可以使用 *set 命令连接(组合)两个或更多字符串。

设置布尔变量|Setting Boolean Variables

变量的第三种数据类型是布尔型,它只能保存 true 或 false 的值,如下所示:

Note that even though boolean values look vaguely the same as string (text) variables, they are not; "Quotation marks" are not needed around the values true or false, and no other values can ever be assigned to a boolean. 请注意,尽管布尔值看起来与字符串(文本)变量有些相似,但它们并不相同;在值 true 或 false 周围不需要使用 "引号",并且布尔变量不能被赋予其他任何值。

更改数据类型|Changing a Data Type

Although it is now possible to effectively change a variable's data type using the *set command (e.g. a string or boolean variable can be *set to a numeric value - or vice-versa - simply by overwriting its existing value with a new value of a different data type), we strongly advise against doing so if you are still relatively new to ChoiceScript. It is easier to keep the game design logic clear in your own mind if you always use a specific set of variables for a specific purpose, and create new variables as needed for any additional purpose. 尽管现在可以通过使用 *set 命令有效地更改变量的数据类型(例如,字符串或布尔变量可以通过用不同数据类型的新值覆盖其现有值,从而被 *set 为数值——反之亦然),但如果您对 ChoiceScript 还相对陌生,我们强烈建议不要这样做。如果您始终将一组特定的变量用于特定目的,并根据需要为任何额外目的创建新变量,将更容易在您自己的脑海中保持游戏设计逻辑的清晰。

choicescript_stats.txt*set

It should be noted that the *set command works differently in choicescript_stats.txt than it does in an ordinary scene file. Unlike for an ordinary scene, on the Stats page it has only a temporary effect, adjusting data or other information for display purposes only. It does not actually save any changes. For example, if you

*set var + 15 on the Stats page, and assuming var previously had a value of 10, it will now display var with a value of 25. However, when the player exits that screen and returns to the game, var will still have the original value of 10. 在状态页面上,并假设变量 var 先前值为 10,现在它将显示变量 var 的值为 25。然而,当玩家退出该屏幕并返回游戏时,变量 var 仍将保持原始值 10。

circle-info

TIP: If your game should require a range of data updating or recalculating on a regular basis - and with the new values actually being saved using *set - we recommend using a *gosub routine for this purpose. 提示:如果你的游戏需要定期更新或重新计算一系列数据——并且需要使用 *set 实际保存新值——我们建议为此目的使用 *gosub 例程。

To properly understand variables and correct use of the *set command, we highly recommend studying the articles on Variable Types and Data Types respectively. 要正确理解变量和 *set 命令的正确用法,我们强烈建议分别学习关于变量类型和数据类型的文章。