Jump to content
Doom989

Proceedure difficulty

Recommended Posts

Hey there, I've been trying to use procedures in my script. My problem is, this does the first if statement under super; then skips the rest and outputs 'it worked'.

I've removed the bitmap strings to shorten for posting.

(Using 3.38 btw)

 

var
x, y: Integer; 
one,two,three,four:TSCARBitmap; 

procedure setting;
begin 
 one := TSCARBitmap.Create('');
 two := TSCARBitmap.Create('');
 three := TSCARBitmap.Create('');  
 four := TSCARBitmap.Create('');

end;

procedure super;
begin
 if FindBitmap(x,y,one,147, 319,1113, 421) then
  begin
   ClickMouse(x+10,y+10,mbleft);
   wait(1000) 

 if FindBitmap(x,y,two,542, 399,944, 664) then
  begin 
   clickmouse(x+5,y+5,mbleft);  
   writeLn('two found')
   wait(5000)   

 if FindBitmap(x, y, three,298, 482,686, 671 ) then
  begin   
    writeLn('three found')
    clickmouse(x+5,y+5,mbleft);  
    wait(4000);  

 if FindBitmap(x,y,four,702, 483,971, 692) then
  begin
     writeLn('Found four')
     ClickMouse(x+5,y+5,mbleft);
     wait(180000);
   end; 
  end;
  end;
  end;    
  end;
begin
repeat
(setting);
writeLn('Setting done')
wait(5000)
super;
writeLn('It worked, waiting.')
wait(10000)  
until false;
end.

Link to comment
Share on other sites

Create "super" as a function instead, which returns as Boolean (True with success).

 

Like this:

 

var
 x, y: Integer; 
 one, two, three, four: TSCARBitmap; 

procedure setting;
begin 
 one := TSCARBitmap.Create('');
 two := TSCARBitmap.Create('');
 three := TSCARBitmap.Create('');  
 four := TSCARBitmap.Create('');  
end;

function super: Boolean;
begin
 Result := False;
 if FindBitmap(x, y, one, 147, 319, 1113, 421) then
 begin
   ClickMouse((x + 10), (y + 10), mbLeft);
   Wait(1000)     
   if FindBitmap(x, y, two, 542, 399, 944, 664) then
   begin 
     ClickMouse((x + 5), (y + 5), mbLeft);  
     WriteLn('two found')
     Wait(5000)   
     if FindBitmap(x, y, three, 298, 482, 686, 671) then
     begin   
       WriteLn('three found')
       ClickMouse((x + 5), (y + 5), mbLeft);  
       Wait(4000);  
       if FindBitmap(x, y, four, 702, 483, 971, 692) then
       begin
         WriteLn('Found four')
         ClickMouse((x + 5), (y + 5), mbLeft);
         Wait(180000);  
         Result := True;
       end; 
     end;
   end;
 end;    
end;

begin
 repeat
   setting;
   WriteLn('Setting done')
   Wait(5000)
   if super then
     WriteLn('It worked, waiting.');
   Wait(10000);  
 until False;
end.

Link to comment
Share on other sites

Create "super" as a function instead, which returns as Boolean (True with success).

 

Like this:

 

var
 x, y: Integer; 
 one, two, three, four: TSCARBitmap; 

procedure setting;
begin 
 one := TSCARBitmap.Create('');
 two := TSCARBitmap.Create('');
 three := TSCARBitmap.Create('');  
 four := TSCARBitmap.Create('');  
end;

function super: Boolean;
begin
 Result := False;
 if FindBitmap(x, y, one, 147, 319, 1113, 421) then
 begin
   ClickMouse((x + 10), (y + 10), mbLeft);
   Wait(1000)     
   if FindBitmap(x, y, two, 542, 399, 944, 664) then
   begin 
     ClickMouse((x + 5), (y + 5), mbLeft);  
     WriteLn('two found')
     Wait(5000)   
     if FindBitmap(x, y, three, 298, 482, 686, 671) then
     begin   
       WriteLn('three found')
       ClickMouse((x + 5), (y + 5), mbLeft);  
       Wait(4000);  
       if FindBitmap(x, y, four, 702, 483, 971, 692) then
       begin
         WriteLn('Found four')
         ClickMouse((x + 5), (y + 5), mbLeft);
         Wait(180000);  
         Result := True;
       end; 
     end;
   end;
 end;    
end;

begin
 repeat
   setting;
   WriteLn('Setting done')
   Wait(5000)
   if super then
     WriteLn('It worked, waiting.');
   Wait(10000);  
 until False;
end.

 

Ahha! that simple, thank you very much for enlightening me!

Also the formatting looks much more visually pleasing than the way I was doing mine.

Link to comment
Share on other sites

Ahha! that simple, thank you very much for enlightening me!

Also the formatting looks much more visually pleasing than the way I was doing mine.

No problem mate, just glad to hear I could help!

 

By the way... Just noticed the waiting part there in mainloop, but you probably got it down already - it should be like this of course:

 

begin
 repeat
   setting;
   WriteLn('Setting done')
   Wait(5000)
   if super then
   begin
     WriteLn('It worked, waiting.');
     Wait(10000);
   end;  
 until False;
end.

 

There is some ways how you could optimize/speedup your code though, I'll write you some code in a moment. :)

Message here if you are interested!

 

-Jani

Link to comment
Share on other sites

No problem mate, just glad to hear I could help!

 

By the way... Just noticed the waiting part there in mainloop, but you probably got it down already - it should be like this of course:

 

begin
 repeat
   setting;
   WriteLn('Setting done')
   Wait(5000)
   if super then
   begin
     WriteLn('It worked, waiting.');
     Wait(10000);
   end;  
 until False;
end.

 

There is some ways how you could optimize/speedup your code though, I'll write you some code in a moment. :)

Message here if you are interested!

 

-Jani

 

I'd be very interested in your assistance. Optimization is always good, and it will help me with future scripts a boat load :)

Link to comment
Share on other sites

I'd be very interested in your assistance. Optimization is always good, and it will help me with future scripts a boat load :)
Hey Doom!

 

Alrightys man! :)

 

So, I would do something like this:

 

const
 SCAN_INTERVAL = 10; // For bitmap scan, to prevent lag? Could be just 0 aswell if it doesn't lag.

var 
 one, two, three, four: TSCARBitmap; 

procedure setting;
begin 
 one := TSCARBitmap.Create('');
 two := TSCARBitmap.Create('');
 three := TSCARBitmap.Create('');  
 four := TSCARBitmap.Create('');  
end;

function FindBitmapW(var x, y: Integer; bmp: TSCARBitmap; XS, YS, XE, YE, interval, maxTime: Integer): Boolean;
var
 timemark: Integer;
begin
 timemark := GetSystemTime;
 repeat
   Result := FindBitmap(x, y, bmp, XS, YS, XE, YE);
   if not Result then
     Wait(interval);
 until (Result or ((GetSystemTime - timemark) > maxTime));
end;

function super: Boolean;
var
 found: Boolean;
 timemark, x, y: Integer;
begin
 Result := False;
 if FindBitmap(x, y, one, 147, 319, 1113, 421) then
 begin
   ClickMouse((x + 10), (y + 10), mbLeft);
   if FindBitmapW(x, y, two, 542, 399, 944, 664, SCAN_INTERVAL, 1000) then
   begin 
     ClickMouse((x + 5), (y + 5), mbLeft);  
     WriteLn('two found');
     if FindBitmapW(x, y, three, 298, 482, 686, 671, SCAN_INTERVAL, 5000) then
     begin   
       WriteLn('three found');
       ClickMouse((x + 5), (y + 5), mbLeft);  
       if FindBitmapW(x, y, four, 702, 483, 971, 692, SCAN_INTERVAL, 4000) then
       begin
         WriteLn('Found four');
         ClickMouse((x + 5), (y + 5), mbLeft);  
         Result := True;
       end; 
     end;
   end;
 end;    
end;

begin
 setting; // We need to do the settings only once, this shouldn't be looped..
 WriteLn('Setting done');
 Wait(5000);
 repeat
   if super then 
   begin
     WriteLn('It worked, waiting.');
     Wait(180000);
   end;  
 until False;
end.

 

As you notice, I also moved setting outside the loop, because settings really require to be ran only once... :P

 

That makes your script a lot smoother in many ways, but of course, you could add in small delay between using each FindBitmapW, but that is totally up to you mate.

 

Regards,

-Jani

Link to comment
Share on other sites

Hey Doom!

 

Alrightys man! :)

 

So, I would do something like this:

 

const
 SCAN_INTERVAL = 10; // For bitmap scan, to prevent lag? Could be just 0 aswell if it doesn't lag.

var 
 one, two, three, four: TSCARBitmap; 

procedure setting;
begin 
 one := TSCARBitmap.Create('');
 two := TSCARBitmap.Create('');
 three := TSCARBitmap.Create('');  
 four := TSCARBitmap.Create('');  
end;

function FindBitmapW(var x, y: Integer; bmp: TSCARBitmap; XS, YS, XE, YE, interval, maxTime: Integer): Boolean;
var
 timemark: Integer;
begin
 timemark := GetSystemTime;
 repeat
   Result := FindBitmap(x, y, bmp, XS, YS, XE, YE);
   if not Result then
     Wait(interval);
 until (Result or ((GetSystemTime - timemark) > maxTime));
end;

function super: Boolean;
var
 found: Boolean;
 timemark, x, y: Integer;
begin
 Result := False;
 if FindBitmap(x, y, one, 147, 319, 1113, 421) then
 begin
   ClickMouse((x + 10), (y + 10), mbLeft);
   if FindBitmapW(x, y, two, 542, 399, 944, 664, SCAN_INTERVAL, 1000) then
   begin 
     ClickMouse((x + 5), (y + 5), mbLeft);  
     WriteLn('two found');
     if FindBitmapW(x, y, three, 298, 482, 686, 671, SCAN_INTERVAL, 5000) then
     begin   
       WriteLn('three found');
       ClickMouse((x + 5), (y + 5), mbLeft);  
       if FindBitmapW(x, y, four, 702, 483, 971, 692, SCAN_INTERVAL, 4000) then
       begin
         WriteLn('Found four');
         ClickMouse((x + 5), (y + 5), mbLeft);  
         Result := True;
       end; 
     end;
   end;
 end;    
end;

begin
 setting; // We need to do the settings only once, this shouldn't be looped..
 WriteLn('Setting done');
 Wait(5000);
 repeat
   if super then 
   begin
     WriteLn('It worked, waiting.');
     Wait(180000);
   end;  
 until False;
end.

 

As you notice, I also moved setting outside the loop, because settings really require to be ran only once... :P

 

That makes your script a lot smoother in many ways, but of course, you could add in small delay between using each FindBitmapW, but that is totally up to you mate.

 

Regards,

-Jani

 

This is awesome! A few things I've never used/seen and they looks useful, thank you very much :)

 

Since your previous post, I've added a great deal to the script, gonna take a while to figure out how to implement all these changes :)

Edited by Doom989
Link to comment
Share on other sites

This is awesome! A few things I've never used/seen and they looks useful, thank you very much :)

 

Since your previous post, I've added a great deal to the script, gonna take a while to figure out how to implement all these changes :)

Sounds like the script is progressing nicely!

 

Heh, those are still fairly "simple" tricks what I added - I would personally use custom types for this, but it would turn out pretty much overkill for simple tasks (and might involve unneeded confusion, unless you understand how types work)...

..but yeah, there's a lot of things you'll be learning once you get it going. :D

 

Good to hear you did learn some new tricks!

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...