🇨🇳
R2Northstar Wiki
Chinese
Chinese
  • 欢迎来到Northstar
  • 加入我们
  • 安装Northstar
    • 基础教程
    • 故障处理
  • Northstar用户手册
    • Mods(模组)
    • 服务器列表
    • 直连服务器
    • 游戏模式
    • 控制台指令
    • 启动参数
    • 在Linux上游玩
  • 常见问题解答
  • 使用 Northstar托管服务器
    • 前期准备
    • 托管私人比赛服务器
    • 托管独立的服务器端
      • 实践经验
      • 在Linux上托管服务器
    • 故障处理
    • 视频教程
  • 修改与开发教程
    • 开始修改
      • 基础修改
      • 教程
      • 参考列表
      • Squirrel(松鼠)脚本
        • 线程处理
        • 基础代码块
        • Respawn(重生)创建的函数
        • 表和数组
        • 回调函数
        • 游戏模式修改
          • 开始修改
        • 自定义设置
          • 关于mod.json文件
          • 关于本地化语言文件
          • 关于Mod(模组)文件
      • 设置语法高光
      • 本地化翻译
      • 收尾工作
    • 开发者
  • 其他
    • 特别感谢
由 GitBook 提供支持
在本页
  • Arrays
  • Tables
  • 2D arrays and Tables of Arrays
  1. 修改与开发教程
  2. 开始修改
  3. Squirrel(松鼠)脚本

表和数组

Within squirrel there are many ways to store information, but when storing an unspecified ammount of information, or storing information on a player-by-player basis, you need to use arrays or tables.

Arrays

Arrays can store large sets of data and are indexed using numbers, starting from 0, and are declared using array<type> arrayname the identifier can be ignored but will result in the array being of the type var.

array<int> numbers = [1,2,3,4,5,6,7,8,9,10]

print(numbers[0])
>>1
print(numbers[5])
>>6

adding and removing values from arrays can be done using .append(value) and .remove(index).

additionally the index of values can be found using the .find function and the length by using the .len() function

array<int> numbers = [1,2,3,4,5,6,7,8,9,10]

print(numbers.find(3))
>>2
print(numbers[5])
>>6
numbers.remove(5)
print(numbers[5])
>>7
print(numbers.len())
>>9
array<int> empty = []
empty.append(5)
print(empty[0])
>>5

Tables

Tables are similar to arrays but with one primary difference, rather than use a numerical index system tables allow you do define your own indexes, similar to pythons dict type.

Creation of a table is done in a similar way to arrays, however may have 2 types declared for the type of the index and the type of the content, much like arrays this will default to var if ignored

table<string, int> numberofletters = {"hello": 5}

unlike arrays however adding values to tables cannot be done using .append or similar means, as the index must also be declared, adding to tables is done using the <- operator like so.

table<entity, int> playerkills = {}
foreach(entity player in GetPlayerArray())
  playerkills[player] <- 5

2D arrays and Tables of Arrays

Another attribute of tables and arrays is that they can store any value type, including tables and arrays themselves. this can be used to store an array within a table, useful if you want to store multiple values related to each index in a single variable

to create a 2d array you simply define the data type as beign an array of arrays like so.

array<array<int>> 2darray = [[1,2,3],[4,5,6],[7,8,9]]
print(2darray[1][1])
>>5
上一页Respawn(重生)创建的函数下一页回调函数

最后更新于3年前