Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Creating an array of images

Recommended Posts

I've avoided using arrays, but I think the times come to start getting a handle on them.


What I've done is make screen captures in order to get all the digits on a game. I then created individual images of each digit, keeping a single color and making it white and turning all the rest of the pixels black. The idea is to store those in an array and then use them as a mask to identify various values in a screen grab.


Here is my failed attempt :


count: integer;
Digit: array of TSCARBitmap;

Function LoadDigit(num:integer):string;
 case num of
   0 : Result := TSCARBitmap.Create('deNrjZuBlgIP/qIABFfzHAfDLYiog0kBiFO' +
   1 : Result := TSCARBitmap.Create('deNpjZ+BhQAb/YQCNCxf8TxyAqMRq5qASBACEeYmK');
   2 : Result := TSCARBitmap.Create('deNrjYuBhgID/GICBAacUXMF/3ABZFtMoBm' +
   3 : Result := TSCARBitmap.Create('deNrjYuBlgID/GICBAacUXMF/3IABGyBDFr' +
   4 : Result := TSCARBitmap.Create('deNrjZuBhQAP///9HY6DJIgNSFfzHAFhlk' +
   5 : Result := TSCARBitmap.Create('deNrjYuBlgIP/GACXOBmyDNgAkbKYxhK0F4' +
   6 : Result := TSCARBitmap.Create('deNrjYuBlQAP/YQCXOKYUHl34NRIphQaIl8Vv' +
   7 : Result := TSCARBitmap.Create('deNrjYuBhgID///9DSDiAi5MNGDAAHin8spRr' +
   8 : Result := TSCARBitmap.Create('deNrjZOBlAIL/GICBAbs4VoBLMQMMECOFyz' +
   9 : Result := TSCARBitmap.Create('deNrjZuBhgIP/qICBAacUpjLiFRA0E6sC/C' +

 For Count := 0 to 9 do
   Digit[count] := LoadDigit(count);
 for count := 0 to 5 do


Unfortunately this keeps giving me a "type mismatch" error. Here is an image to text grab as an example of what I'm going to use it on :


capture := TSCARBitmap.Create('deNrFmDFr40oQx+9L3Ld63+K44hBXPISLY3ETlh' +
   'RBXBFEiiBSBOzC4BQGpwg4TUApAnZhUIqAXKRQ8QoXr3CRwu83Gnm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OV3e' +
   'xFsdKJwk8OqAj2Ak9VRLv04gtVmI2XmQpkXfkaBbY0cPuKoX7ugUZsUxfGeWuN' +
   'Q3koyW6ZEY/X6gfC/Ca6yDBQHxA4zNQaPu4Ka1ATZt+6pPCijTlBAElsuMiNRw' +
   '1suVbEg0oMzrxuhpTLTzWqE39Klb4QYd+WhZ7IJtiNH31QBjm92kJAQLYi9aDf' +
   'IpkiipfURBSlXruDLgAz76DfsqkMD/pUqpOa7Oc4DRy48dGD2K6Q5UQequjhHd' +
   '+bFvgkjbbgRASp22r2rw9F2oE2OQv4hjWkY26dtrmg7aFVETpT2MqB0fcHXOQS' +
   'I4ToyDcq4mrOSOVsyZ1/WqJlZCx3q9RleolAdGcAYsxQIx5aoEmq5RKuEDah19' +
   'l6bhgvE2RjmoFyFtswnR/jJDRX69ShDzw5dmPQVIvQoFmqJ3VbaVgLrsSczto5' +
   '075N5xbVy8CnrcI6saZMZkQcFD1OVdSvegFuJv0VXr6kHu3qQ3BXZW5rKPeqwW' +
   'pQCh43tIrnvmd5yV1EVRc3khwsu9o04ZWlxx7eIK03l/LB8tGZ/LgtalqLSuRa' +
   'VAJUsim1wSd3dMKVyHUgLxFqTTKURlis4DfxnsuGk2B8kVElF3m+8uy6IEuT9y' +
   'upG7oXSUAHAGZZl3fyRFonMpLXoRBKR+kzWL1Af4u78D/OLTh/dB4Ln+DrDYfQ' +


To be honest, I'm not even sure the digit images I made are usable in this manner. So I'm hoping someone can help me out a bit here to get me going in the right direction.

Share this post

Link to post
Share on other sites

You are trying to assign a TSCARBitmap to a String Result.


I would consider creating a custom font. Create a folder in the Fonts folder and in there store a .bmp of each character named for the ascii code (ie upper-case A is 65). Then you can load the font and use SCAR's built-in text functions.

Share this post

Link to post
Share on other sites

Thanks Bixby. I knew that I was mucking up the assignments. It was my first go at it and I couldn't track down relevant information to the process. Or in the very least, understand what I was reading enough to implement it correctly.


So I broke down my .bmp file into individual digits 0 through 9 (using only black and white) and named them according to their Ascii values (ie. 0 is named 48.bmp, 1 is named 49.bmp, etc). I created a directory off the Scar Divi/Work Dir/Font dir named "ClickerHeroFont" (/Scar Divi/Work Dir/Font/ClickHeroFont) and saved those .bmp files to it.


Wrote up a quick script to see if it would find a single digit (zero) located on the game screen. Using gettextatex i pointed it to the upper left corner of where the digit is on the screen. Just my assumption of where to point it at, not really sure. When I try and run the script I get an error code "Runtime Error Line 7 Access Violation at address 00F250D8 in module 'scar.exe'. Read of address is 00000014". Here is the test script :


Program Find_Digits;


 digit := gettextatex(154,278,0,1,false,false,0,2,clWhite,13,false,tr_AlphaNumericChars);
 writeln('digit = '+digit); 


I've actually gotten this far before, but never further (although I hadn't created a font dir and put .bmp files in it before) so just don't know what I'm doing wrong. I've tried both "tr_AlphaNumericChars" and "tr_Digits". Am I overlooking something that needs to point to those .bmp files? Or missing something else obvious?

Edited by Oort

Share this post

Link to post
Share on other sites

Looking at as many posts as I can find on this and found one with some good information (ironically one that looks like you too were having trouble in getting all this to work :) - http://forums.scar-divi.com/showthread.php?t=1734&highlight=creating+font). I think I'm completely butchering the usage of 'chars' in the GetTextAtEx call ... I assumed it was asking maximum number of expected characters, but now understand it is meant to represent what character set is loaded. Probably why I'm getting the access violation. I'm guessing that I need to now figure out how to load the digits character set and then use the 'chars' value to point to them ... Back to digging for info!


(Another Update)


Nailed it! Wow. What a PITA to figure out. Ok. That post I linked to above that you were involved in, Bixby, turned out to be invaluable. What I really struggled with was that there is absolutely no give if you are even a pixel off where it expects to find the text to read. Once I recaptured the digit images to confirm they matched with what was on the screen I reset the x,y coordinates to exactly match the upper left corner of the digit's space. Once I did that I got full matches.


The problem with this whole process is there are so many little tiny details you have to be aware of that aren't well documented anywhere. Most of the dialog that takes place on it assumes the reader is aware of various things or understands various setting meanings. I knew that I was struggling with that before which is why I had opted to try a slower array method. But I'm thankful that you pointed back in this direction Bixby! Here is my final bit of test code that worked :


Program Find_Digits;

 fontset := LoadChars2('C:\Games\SCAR Divi\Work Dir\Fonts\ClickerHeroFont\')
 digit := gettextatex(155,278,0,fontset,false,false,0,0,-1,3,false,tr_Digits);
 writeln('digit = '+digit);
 setmousepos(155,278); //Just to visually see where its looking at 


Thanks for taking the time to respond! :)


- - - Updated - - -


Sigh. Back to the drawing board. It seems that all the characters are written with some kind of anti-aliasing going on so even the same characters have slight pixel differences/shading. Changing the tolerance isn't seeming to really help out. I'll keep messing around with this, but Blah.

Share this post

Link to post
Share on other sites

Managed a time intensive work around. Took a whole lot of screen shots and compared the numbers I found anywhere on the image to the bmp mask. If any pixes in the mask were not covered by a mask created from the screen shot I removed them. After a bit I'm left with a very choppy looking .bmp mask, but it fits in just about every image of that digit created.


Example. If my main mask was 0111110 (where 0 is black and 1 is white) and I took a screenshot of that mask digit from the screen and compared the 2 I would zero out any pixels that didn't exist in the screenshot mask. So I'd SS a digit that would end up being 0011110 I would remove that first 1 from the original digits mask. Lots of trial and error with screenshots. The masks wouldn't exactly match, but enough would to recognize specific digits.


Now this is where Bixby will come on and say "Hey idiot, if you'd done it this other way it would have been much faster and you'd not have to do all that" :P

Edited by Oort

Share this post

Link to post
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.

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