# Thread: Keep getting access violation while trying to count items in inventory on oldschool

1. Registered User
Join Date
Feb 2019
Posts
4
Mentioned
0 Post(s)
Quoted
0 Post(s)

## Keep getting access violation while trying to count items in inventory on oldschool

I cannot figure out why I am getting this error.

-- setupSRL()
---- Setting up SRL...
---- Setup SRL in 0 Seconds
-- setupSRL(): True
Error: Access violation at line 47
Execution failed.

Simba is released under the GPL license.
You are currently using version: 1100
Compiled with FPC version 2.6.1

Here is the script I am working on.

program counting;
{$i srl-6/srl.simba} {$i ETL_LAPE.simba}
const
clientArea:= IntToBox(8 ,4,416,323);
var
backpack:tbox;
backpackslots:TboxArray;
backpackslotwidth,Backpackslotheight:integer;
slot: integer;
x,y:integer

begin
result:=true;
end;

Procedure prepareinvgrid;
var
backpack:tbox;
backpackslots:TboxArray;
backpackslotwidth,Backpackslotheight:integer;
slot: integer;

begin
backpack:= intToBox(564, 214, 719, 457);
Backpackslotwidth:= round(backpack.getWidth/4);
Backpackslotheight:= round(backpack.getHeight/7);
backpackslots:= backpack.split(Backpackslotwidth,Backpackslotheigh t);
//slot:=8;
ETL_Start();
//mouse (backpackslots[slot-1] .getMIddle, MOUSE_LEFT,MOUSE_ACCURATE);
//ETL_DrawBox(backpackslots[slot-1],cLblue,true);
ETL_Drawboxes(backpackslots, true);

end;

Function ItemInSlot(slotnum:integer):boolean;

begin

if findColorSpiral(x,y, 65536, backpackslots[slotnum-1]) then ////ERROR LINE HERE///////////
result := true;
end;

function InvoCount:integer;
var
i,items:integer;
text:string;
begin
for i:= 1 to 28 do
begin
if ItemInSlot(i) then
begin
inc(items);
ETL_Drawbox(backpackslots[i-1],cLblue,true);
end;
end;

text:= 'total items ' +toStr(items);
ETL_DrawTextEx(317,486, Upchars07_s, text, cLblue, false);
result:= items;
end;

function InvoIsFull:boolean;
begin

if InvoCount = 28 then result:= true;

end;

begin
Setupsrl;
ETL_Start;
prepareinvgrid;
InvoCount;
end;

I want the script to draw boxes on the inventory slots and count how many items are in the inventory. Any help would be greatly appreciated. I haven't used simba in years and I am trying my best to use ETL to learn.
Last edited by Tupperware776; 02-05-2019 at 08:42 AM.

2. SRL-6 is for RS3. I'm not familiar with ETL.

e: There are already functions for the things you're trying to do. Here's GetSlotBoxes, but again, it's for RS3. I'm sure SRL has something similar.
Last edited by Citrus; 02-05-2019 at 02:39 PM.

3. Simba Code:
program counting;{$i srl-6/srl.simba}{$i ETL_LAPE.simba}constclientArea:= IntToBox(8 ,4,416,323);varbackpack:tbox;backpackslots:TboxArray;backpackslotwidth,Backpackslotheight:integer;slot: integer;x,y:integerfunction waitClientReady(): boolean;override;beginresult:=true;end;Procedure prepareinvgrid;varbackpack:tbox;backpackslots:TboxArray;backpackslotwidth,Backpackslotheight:integer;slot: integer;beginbackpack:= intToBox(564, 214, 719, 457);Backpackslotwidth:= round(backpack.getWidth/4);Backpackslotheight:= round(backpack.getHeight/7);backpackslots:= backpack.split(Backpackslotwidth,Backpackslotheigh t);//slot:=8;ETL_Start();//mouse (backpackslots[slot-1] .getMIddle, MOUSE_LEFT,MOUSE_ACCURATE);//ETL_DrawBox(backpackslots[slot-1],cLblue,true);ETL_Drawboxes(backpackslots, true);end;Function ItemInSlot(slotnum:integer):boolean;beginif findColorSpiral(x,y, 65536, backpackslots[slotnum-1]) then ////ERROR LINE HERE///////////result := true;end;function InvoCount:integer;vari,items:integer;text:string;beginfor i:= 1 to 28 dobeginif ItemInSlot(i) thenbegininc(items);ETL_Drawbox(backpackslots[i-1],cLblue,true);end;end;text:= 'total items ' +toStr(items);ETL_DrawTextEx(317,486, Upchars07_s, text, cLblue, false);result:= items;end;function InvoIsFull:boolean;beginif InvoCount = 28 then result:= true;end;beginwaitClientReady;Setupsrl;ETL_Start;prepareinvgrid;InvoCount;end;

I believe you're passing in 0 as the slotNumber. That 0 gets evaluated to -1 (0 - 1), which throws an access violation.

4. Registered User
Join Date
Feb 2019
Posts
4
Mentioned
0 Post(s)
Quoted
0 Post(s)
Thanks for the replies. I tried changing

Simba Code:
if findColorSpiral(x,y, 65536, backpackslots[slotnum-1]) then ////ERROR LINE HERE///////////
Simba Code:
if findColorSpiral(x,y, 65536, backpackslots[slotnum:=1]) then ////ERROR LINE HERE///////////
Simba Code:
if findColorSpiral(x,y, 65536, backpackslots[slotnum+1]) then ////ERROR LINE HERE///////////
Simba Code:
if findColorSpiral(x,y, 65536, backpackslots[slotnum+2]) then ////ERROR LINE HERE///////////

With the same result. Srl-6 seems to have some features that go along with the ETL_LAPE include. I realize that srl-6 is built for rs3. I have followed a tutorial on youtube. Good Game Scripts is the name. It is not only for RSPS. Everything compiles fine on the script. But when it runs to the part where it needs to check for the item outline color to check for an item in the slot, it crashes and throws this error.
Last edited by Tupperware776; 02-05-2019 at 04:10 PM.

5. Registered User
Join Date
Jun 2015
Posts
16
Mentioned
0 Post(s)
Quoted
2 Post(s)
It looks like you never initialized your global "backpackslots" array because you overrode it with a local variable in prepareinvgrid function, which gets freed from memory as soon as the function completes. Try removing the local variables from that function and it should work.

6. Registered User
Join Date
Feb 2019
Posts
4
Mentioned
0 Post(s)
Quoted
0 Post(s)
My local variables in the prepareinvgrid; procedure was the issue. I would like to thank all of you for the quick replies. I am now having a range check error with the findcolorspiral function. I have ideas on how to fix it. If I cannot I am going to post back here to request more help. Edit: Scratch that. I just had to load my client and select the window.
Last edited by Tupperware776; 02-05-2019 at 04:29 PM.

7. There are functions in the SRL include that do what you are trying to do. Or is this written for a RSPS? Even in that case, you might copy the SRL functions and edit what you need to in order to work for your application.

8. Registered User
Join Date
Feb 2019
Posts
4
Mentioned
0 Post(s)
Quoted
0 Post(s)
I may try modifying the existing srl. ty for the tip