Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ value from another array) to get at an array value:

This will make .@arrayofnumbers[100] equal to 10.

.@arrayofnumbers[-1] = 20;

This will make .@arrayofnumbers[100] (the last index) equal to 20.

Index numbering always starts with 0 and arrays can hold over 2 billion
variables. As such, the (guaranteed) allowed values for indices are in the
range 0 ~ 2147483647.
Expand Down
6 changes: 5 additions & 1 deletion src/map/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6522,13 +6522,17 @@ BUILDIN_FUNC(getelementofarray)
id = reference_getid(data);

i = script_getnum(st, 3);
if (i < 0 || i >= SCRIPT_MAX_ARRAYSIZE) {
if (std::abs(i) >= SCRIPT_MAX_ARRAYSIZE) {
ShowWarning("script:getelementofarray: index out of range (%" PRId64 ")\n", i);
script_reportdata(data);
script_pushnil(st);
st->state = END;
return SCRIPT_CMD_FAILURE;// out of range
}
if (i < 0) {
struct map_session_data* sd = NULL;
i = cap_value( (script_array_highest_key(st, sd, reference_getname(data), reference_getref(data)) + i), 0, SCRIPT_MAX_ARRAYSIZE );
}

push_val2(st->stack, C_NAME, reference_uid(id, i), reference_getref(data));
return SCRIPT_CMD_SUCCESS;
Expand Down