Welcome to my bitmap tutorial. I will explain to you what bitmaps are, what they can be used for and how the can be used. This tutorial has been edited to work with Simba.
A bitmap is a picture (.bmp), which can be stored as a string in Simba and can be used for whatever reason.
I will teach you how to use bitmaps in 5 easy to understand steps.
Step 1. Creating the bitmap.
First off, click the printscreen button (Left to the scroll lock button). This will take a picture of your screen and save it to your clipboard. Open the run dialog by pressing Windows key + R then typing in mspaint
When paint opens, click Ctrl + V to paste the screenshot. Using the "select" tool drag your mouse over the image that you want to create a bitmap of. When that's done, right click then press cut. Click File > New then when the dialog box comes up asking you to save click No.
In your new canvas, click Ctrl + V again and the bitmap will be pasted into paint. Zoom in as much as you can, and crop it with the select tool a bit more until you have it perfect. It should look something like this
Click File > Save then make sure you select 24 Bitmap
Step 2. Loading the bitmap into memory.
To load the bitmap into the memory you have to use the function BitmapFromString
Simba Code:
BitmapFromString(Width, Height: Integer; data: string);
Lets say for example we wanted to find a bitmap of a copper ore.
When creating a bitmap you should not create it like the above picture. It should look like the picture below.
Now you have to declare a new variable which is an integer, and call it anything, in this case I will call it copperore. Everything the bitmap contains will be stored in this integer, which we will later use to find the bitmap.
Simba Code:
Program new;
Var
copperore:Integer;
Begin
End.
We can then set copper to be the bitmap by using
Simba Code:
copperore := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +
'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +
'/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +
'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +
'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +
'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');
To do this, open Simba then click Tools > Bitmap Conversion.
In the dialog box click Open then load the .bmp file. When you click "To string" you will get the bitmap printed into the debug box. I will show you how to use this.
Step 3. Finding the bitmap
There are many ways to find a bitmap and I will go through the ones most commonly used.
Lets make a procedure that load the bitmap into the memory.
Simba Code:
Procedure FindCopper;
Var //Variables are declared here
copper, X, Y:Integer; //Declare bitmaps as Integers
Begin
copper := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +
'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +
'/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +
'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +
'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +
'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');
If (FindBitmap(copper, X, Y)) Then //This will search the screen for the bitmap
Writeln('Found the copper bitmap') //Tells us it found it
Else
Writeln('Could not find copper'); //Tells us we didn't find it
End;
Just a quick run down of some commonly used bitmap functions.
**The greater colour range you want, the higher the tolerance parameter should be.
Simba Code:
FindBitmap(copper, X, Y);
This is the simplest way to search for a bitmap.
Simba Code:
FindBitmapTolerance(copper, X, Y, 15);
This works just like FindBitmap except you can add some tolerance. I made it 15.
Simba Code:
FindBitmapIn(copper, X, Y, 0, 0, 100, 100);
This will search for the bitmap in a defined area of your screen. In this example it will search for the bitmap from 0, 0 to 100, 100
Simba Code:
FindBitmapToleranceIn(copper, X, Y, 0, 0, 100, 100, 15);
This is FindBitmapTolerance and FindBitmapIn put together.
Simba Code:
FindBitmapSpiral(copper, 50, 50, 0, 0, 100, 100);
This will search for the bitmap from 0, 0 to 100, 100 but starting at 50, 50 (X, Y) and looking outwards from there.
Simba Code:
FindBitmapSpiralTolerance(copper, 50, 50, 0, 0, 100, 100, 15);
Works like FindBitmapSpiral but you can add tolerance.
Simba Code:
FindBitmapRotated(copper, 50, 50, 360, 0, 0, 100, 100);
Works like FindBitmap, but rotates the bitmap after each search by 1 degree. You most likely won't need to use this unless you are finding something that rotates. Will keep rotating until it reaches the angle you define, i set it to 360 so it rotates fully.
Step 4. Clicking the bitmap.
Have the variables ready and the bitmap loaded then we can start to click the bitmap.
How it works: Simba will search the area you define and if it finds the bitmap, it will set the coords of it into the X, Y (Which is why you set these to variables/integers). By using SRL's Mouse function it clicks the X, Y coordinates which is why it is termed "Clicking the bitmap". Example:
Simba Code:
Procedure FindCopper;
{.Include SRL/SRL.scar} //This will add the SRL include to Simba
Var //Variables
copper, X, Y:Integer; //Declare bitmaps as Integers
Begin
SetupSRL; //This sets up SRL
copperore := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +
'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +
'/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +
'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +
'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +
'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');
If (FindBitmapToleranceIn(copperore, X, Y, 0, 0, 100, 100, 25)) Then //This will search the screen for the bitmap
Mouse(X, Y, 5, 5, True); //Clicks on the copper bitmap if found with a randomness of 5
End.
Step 5. Freeing the bitmap from the memory.
After you use a bitmap (even if it doesn't find it) you should always free the bitmap. It's very simple to use:
And that's it. Make sure you put this line after all the finding bitmap and clicking script.
Simba Code:
If (FindBitmapToleranceIn(copper, x, y, 0, 0, 100, 100, 25)) Then
Begin
Writeln('Found the copper bitmap') //Tells us it found it
Mouse(X, Y, 5, 5, true); //Clicks the bitmap with a randomness of 5, 5
FreeBitmap(copper); //This then frees the bitmap
End;
In English: You call the bitmap and then click it, but if you don't free it, it will just stay in the memory doing nothing. When you call this bitmap again, it loads into the memory again and after a while simba will crash or stop working because of a memory leak, so it is VERY important to free it.
That's the basics of bitmaps. If you have mastered this and want still want learn more about bitmaps, continue reading to learn about Advanced Bitmaps.
There are some good ways to use more advanced bitmaps and they come in good use too. They are very easy to use just follow this guide and if you need any help or have any problems please post in this thread.
Simba Code:
FindDeformedBitmapToleranceIn(copper, x, y, 0, 0, 100, 100, 25, 0, false, A);
What this function does, is it looks for a bitmap but skips any part that has the colour of 0 (Black). This is great if the background of the item changes so the script will always find the bitmap.
If we wanted to use FindDeformedBitmapToleranceIn to look for some iron ore, this is what you have to do.
After creating the bitmap, it will look like this.
This is pretty big and has some colours in it that do not need to be used. So using paint, colour in any part of the bitmap black that you do not want the script to look for so it looks like this.
You must remember never to use the whole item as a bitmap, only use part of it.
Now lets say we wanted to find the last picture we can set up the function like this:
Simba Code:
FindDeformedBitmapToleranceIn(IronOre, X, Y, 0, 0, 100, 100, 30, 0, false, acc);
The last 3 parts of this are Range, AllowPartialAccuracy and accuracy. If range is 0 (Which it should be on), it checks pixels at positions that match bitmap we are looking for. If the range is 1, it will check the pixels around the bitmap, if range is bigger, it checks further.
AllowPartialAccuracy allows accuracy that is not a 100% match. This should be set to false. Accuracy returns accuracy of found bitmap to bitmap we are looking for. Put in something such as "acc" or even "a" and declare it as an Extended. (An extended is a variable that can hold decimal places)
Simba Code:
RotateBitmap(iron, 3.14);
This basically just rotates the bitmap if you ever need to, but to be honest I have never needed to use this function.To make is rotate the bitmap 180 degrees set the value to 3.14 (Which is the value of Pi)
If you need any help with bitmaps or have any problems, please post in this thread and please state what you need help with