标识符
Any string that restricts itself to alphabetic characters (a to z and A to Z), digits (0 to 9) and _ qualifies as an identifier. Additionally, identifiers must not begin with a digit. Identifiers are case-sensitive (foo is different from FOO).
字母字符( a 到 z 和 A 到 Z )、数字( 0 到 9 )和 _ 的字符串都可以作为标识符。此外,标识符不能以数字开头。标识符区分大小写( foo 和 FOO 是不同的)。
关键字
The following is the list of keywords supported by the language. Since keywords are reserved words (tokens), they can’t be used as identifiers. Operators (like in, not, and or or) and names of built-in types as listed in the following sections are also reserved.
Keywords are defined in the GDScript tokenizer in case you want to take a look under the hood.
下面是该语言支持的关键字列表。由于关键字是保留字(令牌),它们不能用作标识符。操作符(如 in , not , and 或 or )以及下面列出的内置类型的名称也是保留的。
关键字定义在 GDScript tokenizer 中,假如您想了解其中的内幕
关键字 | 描述 |
---|---|
if | 见 if/else/elif. |
elif | 见 if/else/elif. |
else | 见 if/else/elif. |
for | 见 for. |
while | 见 while. |
match | 见 match. |
break | 退出当前 for 或 while 循环的执行。 |
continue | 立即跳到 for 或 while 循环的下一个迭代。 |
pass | 在语法上要求语句但不希望执行代码的地方使用,例如在空函数中。 |
return | 从函数返回一个值。 |
class | 定义一个类。 |
extends | 定义用当前类扩展什么类。 |
is | 测试变量是扩展给定的类,还是具有给定的内置类型。 |
as | 如果可能,将值转换为给定类型。 |
self | 引用当前类实例。 |
tool | 在编辑器中执行脚本。 |
signal | 定义一个信号。 |
func | 定义一个函数。 |
static | 定义一个静态函数。静态成员变量是不允许的。 |
const | 定义一个常量。 |
enum | 定义一个枚举。 |
var | 定义一个变量。 |
onready | 在脚本所附加的节点及其子节点成为场景树的一部分后初始化变量。 |
export | 保存一个变量及其附加的资源,并使其在编辑器中可见和可修改。 |
setget | 为变量定义setter和getter函数。 |
breakpoint | 调试器断点的编辑器助手。 |
preload | 预加载类或变量。请参见 Classes as resources. |
yield | 协同程序支持。参见 Coroutines with yield. |
assert | 声明一个条件,在失败时记录错误。在非调试构建中被忽略。参见 Assert keyword. |
remote | 网络RPC注释。参见 high-level multiplayer docs. |
master | 网络RPC注释。参见 high-level multiplayer docs. |
puppet | 网络RPC注释。参见 high-level multiplayer docs. |
remotesync | 网络RPC注释。参见 high-level multiplayer docs. |