I have been browsing through the include as I look to try to make myself a better script writer. I happened to stumble across a couple of lines of code that I do not completely understand. I would love some clarification on what they do and how I could use something similar to them in scripts that I write.
I was looking through the backpack file and found this guy:
Simba Code:
(*
waitSlotPixelChange
-------------------
.. code-block:: pascal
function TRSTabBackPack.waitSlotPixelChange(slot, waitTime: integer): boolean;
Returns true if the pixels change in backpack **slot** within **waitTime** . For
example, a raw fish changing to a cooked fish, or an item being consumed.
.. note::
- by Olly & Ashaman88
- Last Updated: 03 January 2013 by Ashaman88 & Olly
Example:
.. code-block:: pascal
if tabBackpack.waitSlotPixelChange(28, 5000) then
writeln('Last backpack slot has changed, we''re done!');
*)
function TRSTabBackpack.waitSlotPixelChange(slot, waitTime: integer): boolean;
var
b: Tbox;
bmp, bmp1: Integer;
t: LongWord;
begin
if (not self.open()) or (not self.isSlotValid(slot))then
exit(false);
b := self.getSlotBox(slot);
t := (getSystemTime() + waitTime);
bmp := bitmapFromClient(b);
bmp1 := createBitmap(b.getWidth(), b.getHeight());
while (not result) and (t > getSystemTime()) do
begin
copyClientToBitmap(bmp1, b.x1, b.y1, b.x2, b.y2);
result := (calculatePixelShift(bmp, bmp1, [0, 0, (b.getWidth() - 1), (b.getHeight() - 1)]) > 0);
if result then
break;
if (SRL_Events[EVENT_ANTIBAN] <> nil) then
SRL_Events[EVENT_ANTIBAN]();
if (not self.open()) then
break;
wait(50 + random(50));
end;
freeBitmaps([bmp, bmp1]);
end;
The parts of this code that I am curious about are:
When I see self.open() or anything that involves 'self.' I get a bit confused. I cannot find anything in the include that has anything do to with the word self other than this:
Simba Code:
{*
__init
------
.. code-block:: pascal
procedure TRSTabBackpack.__init();
Initializes the TRSTabBackpack.
.. note::
- by Olly
- Last Updated: 15 November 2014 by Mayor
Example:
.. code-block:: pascal
tabBackpack.__init();
*}
{$IFNDEF CODEINSIGHT}
procedure TRSTabBackpack.__init();
begin
with self do
begin
name := 'RS Backpack tab';
ID := ID_INTERFACE_TAB_BACKPACK;
tabIndex := TAB_BACKPACK;
parentID := -1;
static := true;
setBounds(gameTabs.tabArea);
__slots[0] := grid(5, 6, 33, 31, 42, 36, point(gameTabs.tabArea.x1 + 25, gameTabs.tabArea.y1 + 22));
__slots[1] := grid(5, 6, 33, 31, 42, 36, point(gameTabs.tabArea.x1 + 25, gameTabs.tabArea.y1 + 50));
end;
end;
{$ENDIF}
I am assuming that this little snippet declares what 'self' does. Am I right with assuming that?
Another part that gets me is this:
Simba Code:
bmp := bitmapFromClient(b);
bmp1 := createBitmap(b.getWidth(), b.getHeight());
What is bitmapFromClient? When I try to open it in SIMBA, it takes me to a 404 error page in my browser.
And finally:
Simba Code:
if (SRL_Events[EVENT_ANTIBAN] <> nil) then
SRL_Events[EVENT_ANTIBAN]();
I understand the majority of these two lines but the confusing part is the 'nil'. Does that mean
'if SRL_Events[EVENT_ANTIBAN] does not equal nothing then..'?
And it also makes me wonder what SRL_Events is because that is not available in the include (or at least the side search in SIMBA).
All clarification is greatly appreciated!