I don't see anything popping out at me that would cause it to not buy the first item. You could try:
Simba Code:
procedure Buy;
begin
if Shop_Screen then
begin
writeln('Shop screen Open');
repeat
writeln('Inventory Still not full');
if (StockShopItem(8) > 20) then
begin
writeln('Bought Item 1');
BuyCoords(90,130,10);
end else //So it will only try buying the second item if there is not >20 items in the shop
if ((StockShopItem(8) < 20) and (StockShopItem(9) < 20)) then
begin
writeln('Bought Item 2');
BuyCoords(90,130,10);
end;
writeln('Item 1 ' + intToStr(StockShopItem(8)));
writeln('Item 2 ' + intToStr(StockShopItem(9)));
until(InvFull);
writeln('Inventory Full Closing Shop');
Close_Shop;
writeln('Closed Shop');
end;
end;
I've never used StockShopItem but I assume it's supposed to return the amount of whatever is in the slot you're specifying? I'd check to be sure that the slot is correct and that there is indeed more than 20 items in it. I know sometimes SRL amount getters break when there's a huge amount of items somewhere but I don't think that would be a problem in a shop.
You could try using something like
Simba Code:
procedure Buy;
begin
if Shop_Screen then
begin
writeln('Shop screen Open');
repeat
writeln('Inventory Still not full');
writeln('Stock of Item 8: ' + intToStr(StockShopItem(8)));
if (StockShopItem(8) > 20) then
begin
writeln('Bought Item 1');
BuyCoords(90,130,10);
end else //So it will only try buying the second item if there is not >20 items in the shop
if ((StockShopItem(8) < 20) and (StockShopItem(9) < 20)) then
begin
writeln('Bought Item 2');
BuyCoords(90,130,10);
end;
writeln('Item 1 ' + intToStr(StockShopItem(8)));
writeln('Item 2 ' + intToStr(StockShopItem(9)));
until(InvFull);
writeln('Inventory Full Closing Shop');
Close_Shop;
writeln('Closed Shop');
end;
end;
That will write in the debug what the result of StockShopItem is. If that doesn't match the amount that's there, you can assume the function is broken because as mentioned the OSRS include hasn't been updated officially in a long time.
For the record, all of the ways you tried using the If X and Y then should work the same I think.