'self' is a keyword referring to the parent type of a typed function.
Consider the following function:
Simba Code:
function someFunction(someInteger:integer):boolean;
It is a 'non-typed' function because it accepts no parent type. It is called like
someFunction(100);
Now consider this function:
Simba Code:
function TPointArray.someFunction(someInteger:integer):boolean;
This is a 'typed' function because it is a function of type TPointArray. It is called like
someTPA.someFunction(100); where
someTPA is a pre-declared variable of type TPointArray.
***
Now, let's continue with our 'typed function' example, so we can demonstrate how 'self' is used. For this example, I will simply wrap the TPA-debugging functions already present in SRL-6.
Simba Code:
function TPointArray.someFunction(someInteger:integer):boolean;
var
i:integer;
begin
for i:= 0 to someInteger do
smartImage.debugTPA(self);
end;
Notice the usage of the 'self' keyword. This keyword simply tells the function to double back and perform operations on it
self.
***
If a user declared three variables of type TPointArray...
Simba Code:
var
tpaa, tpab, tpac:TPointArray;
And then called our
TPointArray.someFunction() on them...
Simba Code:
tpaa.someFunction(50);
tpab.someFunction(50);
tpac.someFunction(50);
The result would be all three TPAs getting debugged to the SMART canvas, 50 times each.
This is because
TPointArray.someFunction() is a function of type TPointArray, and can use the 'self' keyword to refer back to the variable that it is performing operations on (which is to the left of the dot when the call is made).
***
If you'd like a different explanation, read my posts on this thread
https://villavu.com/forum/showthread...99#post1305099 (starting from the post that link will drop you at)
If you're unclear on anything, let me know and I'll explain it a different way
As a bonus, here's some practical examples of 'self' usage which I put in all of my scripts:
Function of type TPointArray, 'self' will refer to the TPA that the function is called on
Simba Code:
function TPointArray.centerPoint():TPoint;
var
tmp:TPointArray;
begin
if (length(self) < 1) then
exit();
tmp := self;
tmp.sortFromPoint(self.getMiddle());
result := tmp[0];
end;
Function of type TRSMinimap, 'self' will refer to the RS Minimap
Simba Code:
procedure TRSMinimap.waitFlagExists(timeout:integer); //waits up to timeout for the flag to be gone
var
t:TTimeMarker;
begin
if (not isLoggedIn()) then
exit();
if tabBackpack.isFull() then
exit();
if (not (self.isFlagPresent())) then
begin
writeWarn('Flag not present, unable to wait while flag exists');
exit();
end;
t.start();
while (t.getTime() < timeout) do
begin
writeDebug('Waiting while the flag exists');
wait(randomRange(250, 500));
if (not (self.isFlagPresent())) then
exit();
end;
end;
E:
Oh and also, Lape is really cool so you can even leave the 'self' keyword out, and the interpreter will still read your code correctly. But that's bad practice.