Jump to content
Doom989

Small problem with script.

Recommended Posts

This little thing I'm trying to write has an odd problem. Sometimes it will do as it should, and the vast majority of the time, just moves the mouse to the top left of the target window and writes 'Found 1'.

 

program New;
var
Bmp: TSCARBitmap; 
x,y:Integer;
begin
 Bmp := TSCARBitmap.Create('deNrTZ+BhcACDHxDAwEArBAYOSODBixeYaPA6p' +
   'oGBtoiQkwa7Y04gIWSjqCWO20mD1zF0BEPFMQMLBqdjBoOTBqdjAFfyWMk=');

if FindBitmap(x, y, Bmp, 537, 484,603, 630) then;
begin
TypeText('z')
MoveMouse(x,y)
writeLn('Found 1')
wait(3000)
end;

if FindBitmap(x, y, Bmp, 537, 484,603, 630) then;
begin
TypeText('z')
MoveMouse(x,y)
writeLn('Found 2')
wait(3000)
end;
end.

 

What I want this to do is basically play a slot machine, detect when a lucky 7 is visible and press z.

Edited by Doom989
Link to comment
Share on other sites

I simply can't get this to work no matter what I try. I'd really appreciate some help.

It constantly says its found 1 when the bmp is not present

program New;
var
Bmp,x,y:Integer;
begin
 Bmp := TSCARBitmap.Create('deNpTY1BlcKAxePDiBRqCiP+gGcC0fWBtZDhBf' +
   'YRp7wDb2EArhGnvgNnIgB0RA3DpRTZh8NuIP6eTasKojaM20s5GMnMHjrJusNl' +
   'IJiKmJB/iNuJPb8PDxqEVjyMhPw6rcpXodhGprcGhaOOJEw/gaIjZSHRLHqeNR' +
   'JswUDYS3y/DlXKIN4H+NlLS13agC6DERgAH2HHk');

if FindBitmap(x, y, Bmp, 408, 366,474, 512) then;
begin
TypeText('z')
MoveMouse(x,y);
writeLn('Found 1')
wait(3000)
end;

end.

Link to comment
Share on other sites

You have semicolon at place where it doesn't belong to.

 

program New;
var
Bmp,x,y:Integer;
begin
 Bmp := TSCARBitmap.Create('deNpTY1BlcKAxePDiBRqCiP+gGcC0fWBtZDhBf' +
   'YRp7wDb2EArhGnvgNnIgB0RA3DpRTZh8NuIP6eTasKojaM20s5GMnMHjrJusNl' +
   'IJiKmJB/iNuJPb8PDxqEVjyMhPw6rcpXodhGprcGhaOOJEw/gaIjZSHRLHqeNR' +
   'JswUDYS3y/DlXKIN4H+NlLS13agC6DERgAH2HHk');

if FindBitmap(x, y, Bmp, 408, 366,474, 512) then; // <= REMOVE that semicolon (
begin
TypeText('z')
MoveMouse(x,y);
writeLn('Found 1')
wait(3000)
end;

end.

Link to comment
Share on other sites

Can't believe it was just that. Thank you very much for your help, one more question, I apologize.

 

Big edit.

program New;
var
Bmp,x,y:Integer;
begin
 Bmp := TSCARBitmap.Create('deNpTYRBg+HGC4UcDEjqBhKguTk+7hitiGEVDH' +
   'xEDhopdSMABBxhidtHHL3S2C5stNElv9LULAIsy7mM=');
repeat
wait(2500)
if FindBitmap(x, y, Bmp, 529, 457,594, 600) then
begin
repeat
TypeText('z')
MoveMouse(x,y)
writeLn('Found 1')
until True;
end;  
wait(2000)  
if FindBitmap(x, y, Bmp, 609, 457,674, 600) then
begin
repeat
TypeText('z')
MoveMouse(x,y)
writeLn('Found 2')
until True;    
wait(2000)
end;
if FindBitmap(x, y, Bmp, 689, 456,754, 601) then
begin
repeat
TypeText('z')
MoveMouse(x,y)
writeLn('Found 3')
until True;
end; 
wait(2000)  
until False; 

end.

 

Problem: script cycles through all if statements alot. so the output is usually 'Found 1, Found 1, Found 3, Found 2' etc.

I'm not sure how to prevent this. I tried using repeats inside the if statements, hoping it would register its been found and move on without coming back to check the first one again

Edited by Doom989
Link to comment
Share on other sites

first, to find the bmp in slot 1 and click Z.

Then move on to slot 2, find it and click Z.

Then slot 3.

But it checks for them all repetedly, so if it has already found 1, it says it found it again and presses z which means it stops slot 2.

Link to comment
Share on other sites

Also, note.. until True; doesn't really work.. What do you mean with the until True;'s?

 

See below:

 

var
 i: Integer;

begin    
 ClearDebug;
 repeat
   Inc(i);
 until True;
 WriteLn('Done! Loop ran ' + IntToStr(i) + ' time[s]...');
end.

 

So you will have to change the until True's for some checks or so.

Link to comment
Share on other sites

I am not exactly sure what you want though, so I can't help too much. :(

 

I would need full explanation of the logic in order to help you out..

But of course, someone else might come help you out here too. :)

 

Anyways, I recommend you try and figure out this problem/logic yourself first, because solving these problems is huge part of learning process for scripting.

The more you solve problems yourself, the faster/better you'll learn.

 

But yeah, if you just cant get it down, try and explain all the things for me and I'll try to get you nice logic for this. :)

Link to comment
Share on other sites

It should,

Start by checking the first set of coordinates for the BMP, when it is found, press 'Z'

Then, look at the second coordinates for the BMP, when its found, press 'Z'

Then, in the third coordinates find the BMP, and press 'Z'

 

And then repeat, but only in that order. The problem is if it finds 1, and cant find 2 or 3, it goes back to 1, finds 1 again, then presses 'Z' again which stops the second spinner in a random spot.

 

I want it to find the BMP at slot one, press Z and then stop looking for 1 until its found 2 and 3.

 

By the way I do strongly agree with what you say. I usually try to make things like this work by myself and in my eyes ive made some progress. But for now I just cannot fathom this part at all.

Edited by Doom989
Link to comment
Share on other sites

Ok, I think I get what you are saying, hold on, I will try and write you logic for this, then I will need you to test it. :)

 

- - - Updated - - -

 

Something like this:

 

var
 bmp: TSCARBitmap;
 x, y: Integer; 

begin
 bmp := TSCARBitmap.Create('deNpTYRBg+HGC4UcDEjqBhKguTk+7hitiGEVDHxEDhopdSMABBxhidtHHL3S2C5stNElv9LULAIsy7mM=');
 repeat
   if FindBitmap(x, y, bmp, 529, 457, 594, 600) then
   begin
     PressKey('z');
     MoveMouse(x, y);
     WriteLn('Found 1');
     while not FindBitmap(x, y, bmp, 609, 457, 674, 600) do
       Wait(1);
     PressKey('z');  
     MoveMouse(x, y);
     WriteLn('Found 2');
     while not FindBitmap(x, y, bmp, 689, 456, 754, 601) do
       Wait(1);
     PressKey('z');
     MoveMouse(x, y); 
     writeLn('Found 3');
     Wait(2500);
   end; 
   Wait(100); 
 until False; 
end.

 

?

Edited by Janilabo
Link to comment
Share on other sites

Hehe, yes. I diddn't notice that was changed. I found that PressKey diddn't work for this script a few days ago.

I've replaced them with TypeText. Script works brilliantly. Thank you so much for your help! At the moment its just a little too slow between detecting the 7 and pressing z, so it often misses lol. But I'll try my best.

 

Thanks again for all your attention and assistance, I'm very grateful :)

Link to comment
Share on other sites

Glad to hear it is working! :D

 

By the way, here is also another way to write this script:

 

const
 INTERVAL = 2000; // Minimum interval between handling the slots?

var
 slot: Integer;
 bmp: TSCARBitmap; 
 slotBoxes: TBoxArray;   

procedure HandleSlot(slot: Integer);
var
 x, y: Integer;
begin
 while not FindBitmap(x, y, bmp, slotBoxes[slot].X1, slotBoxes[slot].Y1, slotBoxes[slot].X2, slotBoxes[slot].Y2) do
   Wait(1);
 TypeText('z');
 MoveMouse(x, y);
 WriteLn('Found ' + IntToStr(slot + 1));
 Wait(INTERVAL);  
end;

procedure ScriptTerminate;
begin
 SetLength(slotBoxes, 0);
 bmp.Free;
end;

begin
 GetClient.Activate; 
 slotBoxes := [box(529, 457, 594, 600), Box(609, 457, 674, 600), Box(689, 456, 754, 601)];
 bmp := TSCARBitmap.Create('deNpTYRBg+HGC4UcDEjqBhKguTk+7hitiGEVDHxEDhopdSMABBxhidtHHL3S2C5stNElv9LULAIsy7mM=');
 Wait(500);                                 
 repeat   
   for slot := 0 to 2 do
     HandleSlot(slot);
   Wait(100); 
 until False; 
end.

 

Enjoy,

-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...