Creat
The *create command is used to declare the permanent variables your game will use to reference and store its data, such as character statistics and other information pertinent to your game. Unlike most other ChoiceScript commands, the *create command can only be used in startup.txt. There is no real limit to the number of different variables you can *create in that file, but each must be uniquely named. *create命令用于声明游戏将用来引用和存储数据的永久变量,例如角色属性及其他与游戏相关的信息。与大多数其他ChoiceScript命令不同,create命令只能在startup.txt中使用。该文件中可create的不同变量数量没有实际限制,但每个变量必须具有唯一名称。
Declaring variables 声明变量
Although it is generally a good idea to design and plan your game in advance - especially such as the character statistics it will use - you may edit startup.txt at any time during the development process to add new variables to your game by adding (or inserting - the order in which they are listed is not important) new create commands to your starting list. 尽管通常建议提前设计和规划游戏——尤其是将使用的角色属性等要素——但在开发过程中,您随时可以编辑startup.txt,通过向初始列表添加(或插入——变量列出的顺序并不重要)新的create命令来为游戏新增变量。
However, not all game data needs to be created at the start of play and stored / updated throughout play. It is very common to use temporary variables for a limited, specific purpose in the game and which, unlike permanent variables, can be declared at any point in any scene .txt file using the temp command. 不过,并非所有游戏数据都需要在游戏开始时创建并在整个游戏过程中存储/更新。使用临时变量来实现游戏中有限且特定的目的非常常见,与永久变量不同,临时变量可以在任何场景的.txt文件中通过temp命令随时声明。
Usage 用法
In startup.txt, each *create command must occupy a line of its own, as shown below. Note that your list of *create commands must be placed in that file after the title, author and scene_list commands, never before. See startup.txt for more information on the precise layout of that file. 在startup.txt中,每个create命令必须独占一行,如下所示。请注意,你的create命令列表必须放置在该文件的title、author和scene_list命令之后,绝不能在此之前。关于该文件具体布局的更多信息,请参阅startup.txt。
*title My Little Adventure
*author Anonymous
*scene_list
startup
chapter1
*create name "Unknown"
*create gold 0
*create backpack falseIn this example, our startup.txt file has the game title and scene_list commands properly preceding the list of starting game variables that we intend to use in our game. Our two example scene starting files - startup and chapter1 - are also listed as required (and that list will grow as we create new scene files for our game and add them to this list in startup.txt). 在这个例子中,我们的startup.txt文件正确地让游戏title和scene_list命令位于我们打算在游戏中使用的起始游戏变量列表之前。我们两个示例场景的起始文件——startup和chapter1——也已按要求列出(随着我们为游戏创建新的场景文件并将它们添加到startup.txt的这个列表中,该列表将会增长)。
The three permanent variables we are creating are called 'name', 'gold' and 'backpack' respectively and each of these is using a different data type, determined by the final piece of information entered on each create line - a "string" value (to store "some text"), a numeric value (0 starting gold in this case), and a boolean value which can only ever be true or false (in this case, no, the player does not begin the game with a backpack and so the starting value has been set to false). See the article on data types for a more detailed explanation of each of the three data types. 我们正在创建的三个永久变量分别名为“name”、“gold”和“backpack”,每个变量都使用了不同的数据类型,这由每条create行末尾输入的信息决定——分别是“字符串”值(用于存储“文本”)、数值(本例中起始金币为0),以及只能为真或假的布尔值(本例中玩家初始不拥有背包,因此起始值设为false)。关于这三种数据类型的详细解释,请参阅数据类型相关文章。
尽管你的游戏很可能使用远超三个变量,但规则保持不变——
每条*create指令必须独占一行
每个变量名必须唯一且不应包含空格;但使用下划线是允许的
每个变量名应仅使用小写字母,且必须始终以字母 a-z 开头,不能是其他字符或数字(但可以在其他位置包含数字,例如在末尾,如 'var6')。
每个变量必须被赋予一个初始默认值,可以是“一些文本”、一个数字,或者真/假
Changing variable values later on 稍后修改变量值
See the *set command for details of how to later change the default starting value of any variable at any point in the game (e.g. when a player chooses their own name, finds some gold, or buys a backpack). 有关如何在游戏中的任意时刻(例如当玩家选择自己的名字、发现一些金币或购买背包时)更改变量的默认初始值,请参阅 *set 命令的详细说明。