基本类型
Lua 类型
nanos world runs Lua 5.4. For more information and tutorials, please refer to the Official Lua 5.4 Reference Manual.
number
Numbers can be integers (64-bit, like 10 or -3) or floats (double-precision, like 3.14). Lua converts between them automatically when needed, e.g. 10 / 2 results in the float 5.0 while 10 // 2 (floor division) results in the integer 5. In this documentation we use integer and float to tell which one a function expects or returns.
string
A sequence of characters (bytes), such as "hello" or 'world'. Strings can hold any binary data and are immutable: functions like string.upper return a new string instead of changing the original one. Use .. to join strings, e.g. "Hello " .. player:GetName().
function
Functions are values like any other: they can be stored in variables and tables, passed as parameters and returned by other functions. That's how callbacks work in nanos world, e.g. Player.Subscribe("Spawn", function(player) ... end).
boolean
Either true or false. In conditions, only false and nil are considered false, everything else (including 0 and the empty string "") is considered true.
nil
Represents the absence of a value. Variables which were never assigned are nil, and many functions return nil when they don't find what you asked for (e.g. Prop.GetByIndex(9999)), so always check for it before using the result.
table
The only data structure in Lua, which works both as an array ({ "a", "b", "c" }, indexed from 1) and as a dictionary ({ name = "John", age = 30 }). Tables grow dynamically and can hold any value, except nil. They are passed by reference: changing a table inside a function changes the original one.
iterator
迭代器允许你使用 for k, v in ipairs() 来遍历表的元素。
any
我们在本文档中使用 any 来表示可以使用任何类型。
varargs
可变值列表。
数值类型
除了 Lua 类型之外,API 上的某些方法还具有特定的数值类型,这些类型在内部会进行转换并采取不同的处理方式。
integer
不带任何小数部分的整数。
float
带有小数点的浮点型。
特殊类型
SpecialPath
nanos world 在加载纹理(.jpg、.png)、**声音(.ogg) **或引用来自 WebUI 的文件时,支持一种特殊类型的路径。它允许任何包或 WebUI 轻松访问来自其他包或资产包的文件。
SpecialPath 是一个字符串输入,它支持以下访问资产或包文件的格式:
引用资产包文件
assets://[ASSET_PACK_PATH]/[PATH/TO/FILE.jpg]
引用包文件
package://[PACKAGE_PATH]/[PATH/TO/FILE.jpg]
访问来自 quaternius 资产包中的 图像 示例:
assets://quaternius/Thumbnails/SK_Revolver_01.jpg
访问来自 sandbox 包中的 .ogg 声音 示例:
package://sandbox/Client/my_awesome_audio.ogg
访问来自 my-fonts 包中的 .ttf 字体文件 示例:
package://my-fonts/Client/Roboto.ttf
SpecialPath 输入同时也支持相对路径和传统路径!
Steam Avatar
Steam 头像是一个特殊的 URL,可以将 Steam 头像作为图片加载到 WebUI 和控件上。
steam-avatar://player_steam_id
此 URL 可以通过 Player:GetAccountIconURL() 自动获取。