SRL Archive - OSR Help

help with StockShopItem


seany

2014-09-23 09:16:58

hello im trying to create a shop buying script and i need to add failsafes to confirm if the shop has an stock left.

i see in the buysell include there is: StockShopItem function

but i cant seem to get it to work.


if Shop_Screen then
writeln('Shop screen Open');
if StockShopItem(8) > 10 then {
writeln('Buy 10 items');
BuyCoords(93,130,10);
Close_Shop;
}

but it does not seem to work, could anyone help me with this?

HTYA

rj

2014-09-23 09:32:15

Because you commented out the part where it buys it, in lape/pascalscript we use begin/end instead of {}

if Shop_Screen then
begin
writeln('Shop screen Open');
if StockShopItem(8) > 10 then
begin
writeln('Buy 10 items');
BuyCoords(93,130,10);
Close_Shop;
end;
end;

{} is considered a comment in lape/pascalscript



Or maybe something in the OSR include is broken, because besides anti-randoms hasn't been updated in 7 months

seany

2014-09-23 09:34:44

oh i didnt realise that! i will give it a try now thanks.

is it possible to writeln the result of StockShopItem(8)?

i have tried

writeln('stock' + StockShopItem(8));

but it didnt work

Kyle

2014-09-23 10:16:40

From: hello to you all
oh i didnt realise that! i will give it a try now thanks.

is it possible to writeln the result of StockShopItem(8)?

i have tried

writeln('stock' + StockShopItem(8));

but it didnt work


Use:
writeln('stock' + intToStr(StockShopItem(8)));

EDIT: I've never used that include so i'm not sure what StockShopItem returns, if it returns an integer than what I wrote above will work. If not, you can try:
writeln('stock' + toStr(StockShopItem(8)));

seany

2014-09-23 11:00:55

From: elfyyy
Use:
writeln('stock' + intToStr(StockShopItem(8)));

EDIT: I've never used that include so i'm not sure what StockShopItem returns, if it returns an integer than what I wrote above will work. If not, you can try:
writeln('stock' + toStr(StockShopItem(8)));


Yes that worked perfectly! Thank you!!

i am trying to run it so when 1 item in the shop is low it will try and buy the next item but the way i ave scripted it, it tries the next item straight away.


begin
if Shop_Screen then
begin
writeln('Shop screen Open');
repeat
if StockShopItem(8) > 5 then
writeln('stock' + intToStr(StockShopItem(8)));
begin
writeln('Bought Item 1');
BuyCoords(93,130,10);
end;
if StockShopItem(8) < 5 then
writeln('stock' + intToStr(StockShopItem(8)));
begin
if StockShopItem(9) > 5 then
writeln('stock' + intToStr(StockShopItem(9)));
writeln('Bought Item 2');
BuyCoords(140,130,10);
end;
until(InvFull);
writeln('Inventory Full Closing Shop');
Close_Shop;
writeln('Closed Shop');
end;
end;

also is there a way to say if (condition) & (condition) then?
and also is there a way to write while ((condition) is false) do

seany

2014-09-23 11:45:06

i think im getting closer but its still not working:


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;
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 have tried this code:

if ((StockShopItem(8) < 20) and (StockShopItem(9) < 20)) then

in these different ways


if ((StockShopItem(8) < 20) and (StockShopItem(9) < 20)) then

if (StockShopItem(8) < 20) and (StockShopItem(9) < 20) then

while ((StockShopItem(8) < 20) and (StockShopItem(9) < 20)) do

while (StockShopItem(8) < 20) and (StockShopItem(9) < 20) do

3Garrett3

2014-09-23 12:10:35

I don't see anything popping out at me that would cause it to not buy the first item. You could try:


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


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.

seany

2014-09-23 12:41:10

From: 3Garrett3
I don't see anything popping out at me that would cause it to not buy the first item. You could try:


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


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.


sorry i should explain better it does buy item 1 but wont buy item 2, instead it just keeps looping until item 1 has X amount of stock again. ill give your suggestions a try and see if i can get it working.

also i cant just use an else because there are 4 different items which i want the script to purchase.

im using the writeln code to confirm that the script is getting the correct amount stock the shop and its correct.

thanks

3Garrett3

2014-09-23 12:50:10

From: hello to you all
sorry i should explain better it does buy item 1 but wont buy item 2, instead it just keeps looping until item 1 has X amount of stock again. ill give your suggestions a try and see if i can get it working.

thanks


Is Item 2 the slot 9? It's possible that you want your if statement to say:

if ((StockShopItem(8) < 20) and (StockShopItem(9) > 20)) then

Because you had it set to only but the second item when 8 and 9 were less than 20, but if you want it to buy 9 then you probably want more than 20 I assume?

seany

2014-09-23 13:03:50

From: 3Garrett3
Is Item 2 the slot 9? It's possible that you want your if statement to say:

if ((StockShopItem(8) < 20) and (StockShopItem(9) > 20)) then

Because you had it set to only but the second item when 8 and 9 were less than 20, but if you want it to buy 9 then you probably want more than 20 I assume?


YES! omg such a simple little error!

thankyou!

3Garrett3

2014-09-23 13:13:05

You're welcome! I hope everything works well for you now. Feel free to ask away if you run into other problems