In this tutorial I'm going to show you several ways you can debug your code.
Often times you will find yourself doing trial and error things while debugging your code until you get something right.
There's 2 main ways you can debug something in Simba:
- You can print variables to see what their holding and/or functions to see what their result is.
- You can draw shapes and/or points to see if you have the coordinates right.
This is going to be a bit of a weird tutorial because we are not creating something. With that said, I'm going to give you some examples!
Let's say you are having problems with zoom or something and want to be sure what zoom level you are at, you can just print it:
begin WriteLn Options.GetZoomLevel; end.
Let's say the result is 50 and you are actually at 100% zoom, now you know something is wrong with
Options.GetZoomLevel and it will affect everything that uses it like
When you are having weird results printing your variables to see if they hold the value they should can help you a lot.
Not only variables, you can also print the result of functions.
A good example for this, is when you have an item and the script seems to not be able to see it. You can test if Simba can actually see it like so:
begin Inventory.FindItem('Mithril bar'); //or Inventory.CountItem('Mithril bar'); end;
If you have a mithril bar and it prints true, everything is fine. If it prints false then something is wrong with
Fixing it is another matter this tutorial is just going to be about debugging.
Another thing you should be aware is that you can draw shapes to see if you have the right coordinates.
Let's look at the motherload script function to count the stuff in the sack for this example:
function TScript.GetSackCount: Int32; var B: TBox; begin B := [20, 42, 63, 61]; Result := OCR.RecognizeNumber(SackCountBox, TOCRShadowRule.Create(20), RS_FONT_QUILL); end;
I do not want to get into OCR (Optical character recognition) too much in this tutorial but in this case I needed to pass it in a
TBox of where the text is located.
The smaller the box the better. In this case you could try to use the box of the whole MainScreen but it wouldn't work because it's too large and it wouldn't read anything and ocr would return gibberish.
Anyway to gather the coordinates at first, I just use the ones Simba gives you in the bottom left corner of the coding window:
Let's redo this from scratch and gather a rough eyeballed TBox coordinates and put them in.
For now there's ignore client modes and use fixed sized only:
function TScript.GetSackCount: Int32; var B: TBox; begin B := [10, 25, 70, 70]; Result := OCR.RecognizeNumber(B, TOCRShadowRule.Create(20), RS_FONT_QUILL); end;
Now if we want to debug this we will want to check 2 things... If we got out
TBox right and more importantly if the result is reading the numbers correctly.
So let's change this temporarily to debug it:
function TScript.GetSackCount: Int32; var B: TBox; begin B := [10, 25, 70, 70]; Debug(B); Result := OCR.RecognizeNumber(B, TOCRShadowRule.Create(20), RS_FONT_QUILL); WriteLn Result; end;
Now this will make 2 things. A debug image will show up with our
TBoxdrawn on it and also, it will print the
And this is the result of running this: As you can see, it's working... It's properly reading the number. However, the TBox is still a bit big for my taste so you can just make it smaller with trial and error until it looks good for you :slight_smile:
You can also use drawing to test other shapes and arrays of shapes. Just type "Debug(" in Simba and look at what pops up in the auto completion for some ideas:
Another good example of something to debug are
TPA is short for
You usually get TPAs when you are finding colors. So let's use this example:
var TPA: TPointArray; begin SRL.FindColors(TPA, 2105392, Inventory.Bounds); end;
For people new to
SRL.FindColors, the first parameter is an empty TPA you give to it that will be returned with a TPA of the colors it found. The second paramenter is the color you want to find,
2105392 is the color of the items shadows in the inventory. And the 3rd parameter is the TBox we want to search, in this case our inventory bounds.
So now... if you want to debug the
TPA to be sure it's being found you could just add
SRL.FindColors like this:
var TPA: TPointArray; begin SRL.FindColors(TPA, 2105392, Inventory.Bounds); Debug(TPA); end;
And the result of this is:
And that's about it!
There's also 3rd way to debug things, using the Simba debugger, but the Simba debugger is not very good and sometimes makes things more confusing. I usually only use it myself to know where things got stuck if a script gets stuck somewhere but we will talk about it another day :slight_smile:
I hope this tutorial wasn't very weird because it's a bit abstract... I'm not teaching how to do something from start to finish, but hopefully you now know a little better how to debug things!