Results 1 to 8 of 8

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

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

    Default 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...
    ---- Client is ready.
    ---- 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

    function waitClientReady(): boolean;override;
    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
    waitClientReady;
    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. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    SRL-6 is for RS3. I'm not familiar with ETL.
    Please use [SIMBA] code [/SIMBA] tags so that your code can be easily read.

    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. #3
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Simba Code:
    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

    function waitClientReady(): boolean;override;
    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
    waitClientReady;
    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. #4
    Join Date
    Feb 2019
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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. #5
    Join Date
    Jun 2015
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    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. #6
    Join Date
    Feb 2019
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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. #7
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    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. #8
    Join Date
    Feb 2019
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I may try modifying the existing srl. ty for the tip

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •