Skip to content

Wrap array-returning APIs #3

@Cheatoid

Description

@Cheatoid

Currently, it is inconsistent and also confusing whether a developer should use 0-based indexing or 1-based indexing.
For example:

print(player.GetAll()[1])

The above code will actually not work, a temporary workaround is available for dealing with this issue:

print(player.GetAll().get(1))

The get method uses 1-based indexing and will therefore return the first player from the table.

Another example is that someone may be tempted to iterate players like so:

foreach (var ply in player.GetAll()) {
    print(ply.Name);
}

However that does not work currently, a temporary workaround is available for dealing with this issue:

player.GetAll().each((ply) => {
    print(ply.Name);
});

By using custom loop API, you will get the expected result.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions