Results 1 to 20 of 20

Thread: Function compiles, But nothing happens?

  1. #1
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Function compiles, But nothing happens?

    Edit: fixed, see last post for new error

    Well i posted this a while a go but i never got an answer. I have made some major improvements to this in order to use it in my WorldMAPWalk function but once again have failed to solve this mystery. If anyone could help me find the reason this function is doing nothing, it would be greatly appreciated.

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    var
      x: Array[0..2] of Integer;

    function ColorCheck(Color: Integer; Smart: Boolean): Boolean;
    var
      Dots, W, H, x, y : Integer;
    begin
      Dots := BitmapFromString(17, 15, 'beNpjYPgPAwxEA2pp+W9' +
           'm9o+HB1nkHxjgNASoXkHhDxvbS1T1QPDmzRusWoDmA9V/ZGA4h6oF' +
           'qP7SpUs47GG8ycCwB8yAizx69Ojo0aNIIlh0Ycgy4lVPMmDn5mOgG' +
           'fj3T/jfPz6S1P/5w/T1K8Pdu8RqAaoHordvGc6cId4eRqD5YPUkhS' +
           'RxIQ8AaQdf5g==');
      GetBitmapSize(Dots, W, H);
      SetTargetBitmap(Dots);
      if(FindColorTolerance(x, y, Color, 0, 0, W, H, 10)or(Color=65536)or(Color=0))then Result:=False
      else Result:=True;
      FreeBitmap(Dots);
      if(Smart)then SetTargetDC(SmartGetDC)
      else ResetDC;
    end;

    function FindGoodPoint(x1, y1, x2, y2, PtNum: Integer; UsedCoords: TPointArray; Smart: Boolean; var Color: Integer):TPoint;  //finds good coords, duh!
    var
      y, x, a: Integer;
    begin
      for y:=y1 to y2 do
        for x:=x1 to x2 do
        begin
          Result.x:=x;
          Result.y:=y;
          Color:=GetColor(x, y);
          if(ColorCheck(Color, SMART))then
            for a:=0 to PtNum-1 do
              if(UsedCoords[a].x<>x)and(UsedCoords[a].y<>y)then Exit;
        end;
      Result.x:=-1;
      Result.y:=-1;
    end;
    {*******************************************************************************
    function CheckMovement(MinPoints, MaxPoints: Integer): Integer;
    By: Macrosoft
    Description: NumberOfPoints is the amount of referance points
                   you would like the function the use.  The higher
                   this is set, the more accurate, but also the
                   more slow.
          For Result[0]:
                 Returns 0 if stuck.
                 Returns 1 if not moving.
                 Returns 2 if moving.
          For Result[1]:
                 Returns the number of points used.
                 Returns 0 if not enough points were able to be made.
    *******************************************************************************}

    function CheckMovement(MinPoints, MaxPoints: Integer; SMART: Boolean): array of Integer;
    var
      RPoint: array of Tpoint;
      RColor: array of Integer;
      S, NColor, a, PtsUsed: Integer;
    begin
      SetArrayLength(Result, 2);
      SetArrayLength(RPoint, MaxPoints);
      SetArrayLength(RColor, MaxPoints);
      for a:=0 to MaxPoints-1 do
      begin
        RPoint[a]:=FindGoodPoint(570, 33, 683, 135, a, RPoint, SMART, RColor[a]);
        if(RPoint[a].x=-1)then Break;
      end;
      if(a+1<MinPoints)then
      begin
        WriteLn('Not enough points were found');
        Result[1]:=0;
        Exit;
      end;
      SetArrayLength(RPoint, a+1);
      SetArrayLength(RColor, a+1);
      SetArrayLength(NColor, a+1);
      Wait(300);
      PtsUsed:=a;
      for a:=0 to PtsUsed do
      begin
        NColor:=GetColor(RPoint[a].x, RPoint[a].y);
        if(not(NColor=RColor[a]))then
        begin
          if(ColorCheck(NColor, SMART))then
          begin
            Result[0]:=2;
            WriteLn('We are moving!');
            Result[1]:=PtsUsed+1;
            WriteLn(IntToStr(PtsUsed)+' points used');
            Exit;
          end;
        end else
        begin
          if(S=15)then s:=0 else
          begin
            Wait(150);
            a:=a-1;
            S:=S+1;
          end;
        end;
      end;
      if(FlagPresent)then
      begin
        WriteLn('We are stuck');
        Result[0]:=0;
      end else
      begin
        WriteLn('We have stopped!');
        Result[0]:=1;
      end;
      Result[1]:=PtsUsed+1;
      WriteLn(IntToStr(PtsUsed)+' points used');
    end;

    {*******************************************************************************
    function WaitForStop(SMART: Boolean): Integer;
    By: Macrosoft
    Description: Waits until the character stops moving.
    NumOfPts is the amount of referance points
        you would like the function the use.  The higher
        this is set, the more accurate, but also the
        more slow.
    Returns 1 if you are caught on something and the flag
      remains while you are still
    Returns 2 if stopped.
    *******************************************************************************}


    function WaitForStop(MinPts, MaxPts: Integer; Smart: Boolean): Integer;
    var
      Strikes, SStrk: Integer;
      i: array of Integer;
    begin
      SStrk:=0;
      Strikes:=0;
      SetArrayLength(i, 2);
      repeat
      begin
        i:=CheckMovement(MinPts, MaxPts, Smart);
        if(i[1]=0)then
        begin
          WriteLn('Error with CheckMovement');
          Result:=0;
        end;
        if(i[0]=1)then Strikes:=Strikes+1 else Strikes:=0;
        if(i[0]=0)then SStrk:=SStrk+1 else SStrk:=0;
      end;
      until(Strikes=2)or(SStrk=2);
      if(SStrk=2)then
      begin
        Writeln('You are caught on something!');
        Result:=1;
        Exit;
      end;
      Writeln('Walked to destination!');
      Result:=2;
    end;

    begin
      SetupSRL;
      ActivateClient;
      CheckMovement(2, 4, False);
    end.

    Thanks in advance!

    Macrsoft

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, California
    Posts
    276
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    What is it supposed to do, maybe I could help you.
    Current Project: All In 1 Falador Script - 20% DONE

  3. #3
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It finds a few points that are not occupied by "bad colors" such as people dots and npc dots (because they change even if you arent moving). Then it waits a bit and checks if these points have changed color. If one of them has, then we are moving. If none of them have changed then we are not. If we are not moving and the flag is present then we are suck in a building etc. If when checking a point to see if it's color has changed the color has changed to a "Bad color" (detected using colorcheck) then it waits a bit and then subtracts one from the index (a) so that it repeats that point again.

    That help?

    Feel free to ask questions if you need clarification.

    Thanks so much for your interest in helping me! (I may rep ++ just for that)

    -Macrosoft

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, California
    Posts
    276
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh ya! now I remember, I tried to use this is one of my scripts, didn't work so I took it out and didn't really think of it until now. I'll take a look at it and edit if I found or not found anything.
    Current Project: All In 1 Falador Script - 20% DONE

  5. #5
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    K, thanks so much.

  6. #6
    Join Date
    Jun 2008
    Location
    San Diego, California
    Posts
    276
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well, I couldn't find anything, with my knowledge. I would suggest you either come in the SRL IRC channel, scripter's with much more knowledge than me are in there(Link of how to is at bottom) or if you don't have an IRC client you can go to www.mibbit.com and the server is Freenode.net and channel name is #SRL. Or you can put WriteLn's after each thing it does and debug it that way(That's what I do to my functions) and where it doesn't write is most likely where your problem is.

    How to join the IRC channel.
    http://www.villavu.com/forum/showthr...t=join+channel

    I hope you get it working, this could come in very good use!
    Current Project: All In 1 Falador Script - 20% DONE

  7. #7
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Rep++ for your effort

    Thats whats so puzzling, I have put a writeln on EVERY possible outcome yet nothing is written...

    Ill try IRC.

    Edit: Ty Method and ss23, Im a dumbass

  8. #8
    Join Date
    Jan 2007
    Location
    Hamilton, New Zealand
    Posts
    177
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    win
    <3 Delicious Loli
    15:59 [Putnam] I suck
    15:59 * ss23 pushes Putnam to his knees - Prove it.
    15:59 [Putnam] ss23, there's really no other way to stay fit in this town

  9. #9
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by ss23 View Post
    win
    He speaks the truth!
    :-)

  10. #10
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i feel like such a dumb ass right now you have no idea.

    Edit: [Runtime Error] : Exception: Can't create compatible DC in line 17 in script

    if this is another dumb mistake...i will be pissed

    g'night

  11. #11
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Well, you told me to post telling you to try setting the target DC using GetBitmapDC (SetTargetDC(GetBitmapDC)), but honestly, I have no idea what's causing your problem. Sorry.
    :-)

  12. #12
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I think that does the same thing as targetbitmap

    Anyone know what ResetDC does, I thought it resets the DC to the Client but i may be incorrect.

  13. #13
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    procedure ResetDc;
    Sets the device context of SCAR's selected window as target for SCAR's colorfinding functions.
    That's what Scar manual says, so resets it to client as you said.
    SetTargetBitmap does work the same GetBitmapDC and SetTargetDC - I've done it a lot.

    Anyway, runs fine for me with just ColorCheck both with and without Smart set to false on color 255 and 0, so it may just be your Scar misbehaving when it needs restart.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  14. #14
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Does anyone know what resetdc does? That may be the problem. I thought ResetDC made it so that all the color searching functions etc went back to the client...

    method: Ill try what you said, but i think its the same as what i have

  15. #15
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Macrosoft View Post
    Does anyone know what resetdc does? That may be the problem. I thought ResetDC made it so that all the color searching functions etc went back to the client...

    method: Ill try what you said, but i think its the same as what i have
    ResetDC sets the device context of SCAR's selected window as target for SCAR's colorfinding functions. I find it useful for shutting down computers regarding of whether the user of the script uses the script with SMART or not.

    (To shut down the computer, SCAR has to open up the command prompt, and type in stuff there.)

  16. #16
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    EDIT: Mixster: Im so sorry I missed your post! I must have had a lag or something. If it works for you its probably my cheap computer screwing up (as usual) so ill just put it in worldmapwalk and see what happens.

    Actually, since i cant test it, can you tell me how fast it works? It should work fast. Also, what version of scar are you using? My computer may be doing its job after all...

    Im gunna rep++ you in the morning (I rep++ anyone who attempts to help me because nobody helps me otherwise )

  17. #17
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Took 0.713970406410608 ms

    That's using nielsie's timing thing it the test corner (returned 0 GetSystemTime checks) with 255 and false as inputs. Testing several times with different colours resulted in a range from 0.6 to 1.1ms
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  18. #18
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    what version of scar?

    wait, checkmovement or colorcheck works?

  19. #19
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Tested ColorCheck on Scar 3.15b - assumed it was ColorCheck due to the error being given in the ColorCheck function.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  20. #20
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    colorcheck works fine for me as well but it screws up when i run checkmovement

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Procedure compiles but doesnt do anything
    By impiwimpi in forum OSR Help
    Replies: 3
    Last Post: 02-02-2009, 07:52 AM
  2. TPA Trouble [Compiles but does nothing]
    By Claymore in forum OSR Help
    Replies: 4
    Last Post: 07-08-2008, 06:00 PM
  3. Function Compiles and then...nothing?
    By Macrosoft in forum OSR Help
    Replies: 12
    Last Post: 06-07-2008, 10:40 PM
  4. need help, script compiles right but work?
    By shadowrec0n in forum OSR Help
    Replies: 9
    Last Post: 02-15-2008, 09:09 PM
  5. it compiles but does nothing my script not working
    By ShowerThoughts in forum OSR Help
    Replies: 3
    Last Post: 08-23-2007, 09:01 PM

Posting Permissions

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