I'm trying to write a looting function that right clicks on the loot pile, checks if the items in the pile matches the items declared in a string array, and then increments the number of times it has to loot by 1.
Code:
program new;
{$define SMART}
{$i srl/osr.simba}
{$i srl/shared.simba}
{$i RSWalker/Walker.simba}
const
lootItems = ['Bones', 'of Wine', 'platebody', 'Arrows', 'rune'];
var
i, l, dropCount: integer;
opts: TOptionArray;
begin
if ChooseOption.Open() then
begin
opts := chooseOption.getOptions();
dropCount := 0
for l := 0 to high(length(lootItems)) do //detect the number of loot items
begin
if opts[0].str.Endswith(lootItems[l]) then
begin
dropCount := dropCount + 1;
writeln(dropCount);
end
end
end
end;
When I try running the code with 3 valid items on the ground, it returns an index range error at the red highlighted line above.
Code:
Runtime error: "Index out of range (index:5, low:0, high:4)" at line 23, column 43 in file
I can't figure out why high is still returning 4 if it is checking for the length of the lootItem string array. I figured a quick fix would be to do high(length(lootItems)+1) but the high length is still 4. Is there something I'm missing here?