Results 1 to 11 of 11

Thread: Function not returning a value

  1. #1
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default Function not returning a value

    Sorry for being bothersome, but I'm stuck again

    I've got a function in my script which has to return a string. The string is just text copied from runescape's screen. Now, the function on its own works flawlessly but when I introduce it to the rest of the script it works once in ten tries.

    The function(s):

    Simba Code:
    function GetBuyPrice: string;
    begin
       result := GetNumerals(GetTextAtExWrap(117, 287, 327, 300, 0, 10, 1, 39372, 5, 'StatChars'));
    end;

    Simba Code:
    function GetSellPrice: string;
    begin
       result := GetNumerals(GetTextAtExWrap(117, 287, 327, 300, 0, 10, 1, 39372, 5, 'StatChars'));
    end;

    The entire script so far (I know the quality of it is bad, it's my first attempt at scripting something major):

    Simba Code:
    program New;
      {$i SRL/SRL.scar}
      {$i srl/srl/misc/grandexchange.scar}
    var
      BuyIMG, SellIMG, Item1X, Item1Y: integer;

    function isBuyOpen: boolean;
    var
    x, y: integer;

    begin
       BuyIMG := BitmapFromString(11, 14, 'meJxjYEAC706AEB5AMwXCUvJQKW' +
            'SEJKsV3QFEyLJALkgXTIFB3QZh4wQggsgCGZJO1WoJvRA1QJJHydg' +
            'gczZQF6+SIwRB1OulTQfKAhGXij5QUNImSTW4Scm3CoiADCDSTpgE' +
            'VwA0BKhGxqNazrcRqBGCJCL74Aoghkg4FgPVAK2DIKHwXjQTgAoUg' +
            'zqAhgARUBaiAOIXuAkQJOBRAERwWYhfMBFECgD511mR');
       Result :=  (FindBitmapIn(BuyIMG, x, y, MSX1, MSY1, MSX2, MSY2));
       FreeBitmap(BuyIMG);
    end;

    function isSellOpen: boolean;
    var
    x, y: integer;

    begin
      SellIMG := BitmapFromString(11, 14, 'meJxjYEAC6/6BEC4AkcWlBlkWjz' +
            'k4pISl5CEIogDKRpLViu6AIIgCCBuuBsgwyJwtbJwARFATjBMknar' +
            'VEnohaoAkj5IxUA1QF6+SIwRB1OulTYdYx6WiDxSUtElSDW5S8q0C' +
            'IiBDNapfKmYiXAHQEKAaGY9qOd9GoEYg0s+cIxTeC1cAMUTCsRioB' +
            'mgdBCErgJgAVKAY1AE0BIiAshAFEHfCTYAgAY8CIEILDUwEkQIAEO' +
            'dcMw==');
      Result :=  (FindBitmapIn(SellIMG, x, y, MSX1, MSY1, MSX2, MSY2));
      FreeBitmap(SellIMG);
    end;

    Procedure WalktoSymbol;
    var
      x, y: integer;

    begin
      FindColorTolerance(x, y, 2216175, MMX1, MMY1, MMX2, MMY2, 20);
      Mouse(x, y, 5, 5, True); //Clicks on the bank symbol
    end;

    procedure OpenGE;
    var
      x, y: integer;

    begin
      If (FindObj(x, y, 'Grand Exchange clerk', 6325165, 20)) then
        begin
          Mouse(x, y, 5, 5, False); //Right clicks the clerk
          Mouse(x, y + 49, 2, 2, True);  //Clicks on exchange
          Wait(2000 + Random(500));
          If InGE then
            begin
              exit;
            end;
        end else
          MakeCompass('s');
          Wait(1500 + Random(500));
          FindObj(x, y, 'Grand Exchange clerk', 3679532, 20);
          Mouse(x, y, 5, 5, False); //Right clicks the clerk
          Wait(100);
          Mouse(x, y + 49, 2, 2, True); //Clicks on exchange
    end;

    procedure ClickBack;
    begin
      While isBuyOpen or isSellOpen do
        Mouse(45, 298, 5, 5, True); //Clicks the arrow to get back
    end;

    procedure GettingGEOpen;
    begin
      If isBuyOpen or isSellopen then
        ClickBack;
      If InGE then
        exit;
      If not InGE or not isBuyOpen or not isSellopen then
        WalktoSymbol;
        Wait(5000 + Random(1000));
        OpenGE;
        Wait(1000 + Random(500));
    end;

    function GetNumerals(const s: string): string;  //By Echo_
    var
      i, j: Integer;
      numArray: array of string;
    begin
      numArray := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
      for i := 1 to High(s) do
        for j := 0 to High(numArray) do
        begin
          if not (s[i] = numArray[j]) then Continue;
          Result := Result + s[i];
        end;
    end;

    function isSlotFree: boolean;
    begin
      While not (GEIsSpotFree(1)) or not (GEIsSpotFree(1)) do
        begin
          GEAbortAll;
          GERecoverAll;
        end;
        result := True
    end;

    function GetMidPrice: integer;
    begin
      result := StrToInt(GetNumerals(GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars')));
    end;

    function GetSellPrice: string;
    begin
       result := GetNumerals(GetTextAtExWrap(117, 287, 327, 300, 0, 10, 1, 39372, 5, 'StatChars'));
    end;

    function GetBuyPrice: string;
    begin
       result := GetNumerals(GetTextAtExWrap(117, 287, 327, 300, 0, 10, 1, 39372, 5, 'StatChars'));
    end;

    procedure SetPrice1;
    begin
      Mouse(385, 222, 5, 5, True); //Clicks on the '...' to enter a custom price
      wait(1000 + Random(500));
      SendKeys(IntToStr(GetMidPrice * 3), 200);
      SendKeys(chr(13), 200)
      Wait(500 + Random(500));
      Mouse(263, 290, 5, 5, True); //Clicks confirm
    end;

    procedure SetPrice2;
    begin
      Mouse(385, 222, 5, 5, True); //Clicks on the '...' to enter a custom price
      wait(1000 + Random(500));
      SendKeys(IntToStr(GetMidPrice * 2), 200);
      SendKeys(chr(13), 200)
      Wait(500 + Random(500));
      Mouse(263, 290, 5, 5, True); //Clicks confirm
    end;

    procedure SetPrice3;
    var
      decimal: Extended;

    begin
      Mouse(385, 222, 5, 5, True);   //Clicks on the '...' to enter a custom price
      wait(1000 + Random(500));
      decimal := GetMidPrice * 1.3
      SendKeys(FloatToStr(decimal), 200);
      SendKeys(chr(13), 200)
      Wait(500 + Random(500));
      Mouse(263, 290, 5, 5, True); //Clicks confirm
    end;

    procedure SetPrice4;
    var
      decimal: Extended;

    begin
      Mouse(385, 222, 5, 5, True); //Clicks on the '...' to enter a custom price
      wait(1000 + Random(500));
      decimal := GetMidPrice * 1.15
      SendKeys(FloatToStr(decimal), 200);
      SendKeys(chr(13), 200)
      Wait(500 + Random(500));
      Mouse(263, 290, 5, 5, True);//Clicks confirm
    end;

    procedure FindHigh;
      begin
        If InGE and GEIsSpotFree(1) then
          begin
            GEBuyAt(1);
            SendKeys('Feather', 150);
            Wait(2000 + Random(500));;
            If GetTextAtExWrap(64, 342, 115, 354, 0, 10, 1, 23200, 5, 'SmallChars') = 'Feather' then
              begin
                Mouse(87, 351, 5, 5, True); //Clicks on the feather in the list
                Wait(1000 + Random(1000));
                Mouse(72, 220, 5, 5, true); //Clicks on the quantity 1
                Wait(1000 + Random(1000));
                If GetMidPrice > 500000 then
                  begin
                    SetPrice4;
                  end else
                      If (GetMidPrice < 500000) and (GetMidPrice > 100000) then
                        begin
                          SetPrice3;
                        end else
                            If (GetMidPrice < 100000) and (GetMidPrice > 10000) then
                              begin
                               SetPrice2;
                              end else
                                  If GetMidPrice < 10000 then
                                   begin
                                    SetPrice1;
                                   end;
                While not InGE do
                  begin
                    Sleep(100);
                   end;
                Wait(1500 + Random(500));
                Mouse(103, 139, 5, 5, True); // Click on the trade offer once complete
                Wait(1500+ Random(500));
                Writeln('Getting Sell Price');
                GetSellPrice;
                Writeln('Got Sell Price');
                Mouse(415, 297, 5, 5, True); //Clicks on the first item to collect it
                Wait(300 + Random(300));
                Mouse(465, 297, 5, 5, True); //clicks on the second item to collect it
                Wait(300 + Random(300));
              end else
                Writeln('Item not found.');
          end else
            GettingGEOpen;
      end;

    procedure FindLow;

    begin
      While not InGE do
        begin
          Wait(1000);
        end;
       GESellAt(1);
       FindColorTolerance(Item1X, Item1Y, 10197922, MIX1, MIY1, MIX2, MIY2, 20);
       Mouse(Item1X, Item1Y, 5, 5, True); //Clicks on the feather's coords
       Wait(200 + Random(250));

       Mouse(283, 222, 5, 5, True); // Decrease 5%
       Wait(100 + Random(100));
       Mouse(283, 222, 5, 5, True); // Decrease 5%
       Wait(100 + Random(100));
       Mouse(283, 222, 5, 5, True); // Decrease 5%
       Wait(100 + Random(100));

       Mouse(263, 290, 5, 5, True); // confirm
       Wait(500+ Random(500));
       Mouse(103, 139, 5, 5, True); // Click on offer
       Wait(500+ Random(500));
       repeat
       Writeln('Getting Buy Price');
        GetBuyPrice;
       Writeln('Got Buy Price');
       until((GetBuyPrice = '12') or (GetBuyPrice = '13') or (GetBuyPrice = '14'));
       Wait(1000+ Random(500));
       Mouse(415, 297, 5, 5, True); //click on collect money
       Wait(300 + Random(300));
    end;

    procedure Loop;
    begin
      GettingGEOpen;
      FindHigh;
      FindLow;
    end;
    begin
      ClearDebug;
      SetupSRL;
      MouseSpeed := 10;
      Loop;
      Writeln(GetSellPrice);
      Writeln(GetBuyPrice);
    end.

    What is returned:

    [QUOTE=HT BaaFly;847110]
    Code:
    SRL Compiled in 0 msec
    coords: 41, 164
    coords: 41, 164
    Getting Sell Price
    Got Sell Price
    coords: 41, 164
    Getting Buy Price
    Got Buy Price
    
    
    Successfully executed.
    All help is greatly appreciated
    Last edited by HT BaaFly; 11-20-2011 at 09:58 AM.

  2. #2
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Before you call GetBuyPirce/GetSellPrice add a writeln

    One saying Wreiln('Getting Buy Price') and another for the sell.
    That way you can see if the functions are even being called or not.

    Run the script and tell me if you see those come up in the debug box.

  3. #3
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Sure, just a minute

  4. #4
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Code:
    SRL Compiled in 0 msec
    coords: 41, 164
    coords: 41, 164
    Getting Sell Price
    Got Sell Price
    coords: 41, 164
    Getting Buy Price
    Got Buy Price
    
    
    Successfully executed.
    *Edited OP for this new source code*

  5. #5
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Hmm quite odd, and you say when you call any of them (GetBuyPrice or GetSellPrice) alone you are SURE they work? Odd

  6. #6
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Yup, I've just made sure again

  7. #7
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Oh also between the getting and got, and after the function have it writeln the actual price durf!
    Like

    Simba Code:
    Writeln('Getting Sell Price');
                GetSellPrice;
                WriteLn(GetSellPrice);
                Writeln('Got Sell Price');

    And same with buy price.

  8. #8
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Going to bed now, just letting you know so you won't be eagerly awaiting an answer from me anytime soon, good luck!

  9. #9
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    It's working now but I don't understand this, what difference does it make if the Writeln is in the loop instead of in the same procedure as the GetSellPrice or GetBuyPrice. Anyway, thanks a lot for your help and have a goodnight

  10. #10
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Are you talking about the debug writelns we put in (getting/ got price) or the written that tells you the actual amount? If you're talking about actual amount then you actually never had a written for it, your function simply grabbed the buy/sell price and that's it, you never told the script to actually do anything with it besides grab it, which is why we needed the writeln(buyprice) or sell price. Get it? Typing this from phone sorry for any typos! Anywyas glad you got it worning woo!!

  11. #11
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    nah I was talking about the writelns in the main loop but anyway, it's all solved now, thankfully. the script is nearing completion so i'll release it in the first script section soon for people to look at (don't expect something great)

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
  •