SRL Archive - OSR Help

Free DTMs


Polack

2015-04-09 22:23:00

Is this sufficient enough to free the DTM's and prevent memory leaks?

Procedure Eat;
var
Food, x, y: integer;

begin
Food:= DTMFromString('mlwAAAHicY2dgYOhnYmCYA8SLgXgWE4T345asdfdsfYj/ANWyAGkBIBYB4unVgkARRqyYiwE3wK4DgqEAACT+BqY=');
begin
if FindDTM(Food, x, y, MIX1, MIY1, MIX2, MIY2) then
writeln('Nom');
MMouse(x, y, 1, 1);
If(IsUpText('Eat')) Then
Mouse(x, y, 0, 0, True);
end else
begin
if not FindDTM(Food, x, y, MIX1, MIY1, MIX2, MIY2) then
Logout;
end;
FreeDTM(Food);
end;

Ian

2015-04-09 22:46:51

I think the best way is to load up all the DTMs used in the script at the beginning, and free them when the script terminates. You can do that by having a procedure like this that is called at the beginning of the script (After you setupSRL is a pretty good place)

procedure loadMyDTMs;
begin
Food:= DTMFromString('blablabla...');
MoarFood:= DTMFromString('blablabla...');
addOnTerminate('freeMyDTMs');
end;
and before the loadMyDTMs procedure in the script, place a procedure like this:

procedure freeMyDTMs;
begin
FreeDTM(Food);
FreeDTM(MoarFood);
end;

The addOnTerminate in the procedure that creates the DTMs will make sure that the DTMs are freed when the script terminates, so you don't need to worry about freeing them after you use them.

This way also has the advantage that you only have to think about the DTMs once, and you can use them anywhere else in your script.

NOTE: instead of having the DTMs be variables in each function, have them as global variables so they persist between functions.

NKN

2015-04-09 23:02:36

Lemme know if this works, wrote it in the browser.



Procedure Eat;
var
Food, x, y: integer;

begin
try
begin
Food:= DTMFromString('mlwAAAHicY2dgYOhnYmCYA8SLgXgWE4T345asdfdsfYj/ANWyAGkBIBYB4unVgkARRqyYiwE3wK4DgqEAACT+BqY=');
if FindDTM(Food, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
writeln('Nom');
MMouse(x, y, 1, 1);
If(IsUpText('Eat')) Then
Mouse(x, y, 0, 0, True);
end else
begin
if not FindDTM(Food, x, y, MIX1, MIY1, MIX2, MIY2) then
Logout;
end;
end;
finally
FreeDTM(Food);
end;

end;

Polack

2015-04-09 23:21:34

From: BMWxi
I think the best way is to load up all the DTMs used in the script at the beginning, and free them when the script terminates. You can do that by having a procedure like this that is called at the beginning of the script (After you setupSRL is a pretty good place)

procedure loadMyDTMs;
begin
Food:= DTMFromString('blablabla...');
MoarFood:= DTMFromString('blablabla...');
addOnTerminate('freeMyDTMs');
end;
and before the loadMyDTMs procedure in the script, place a procedure like this:

procedure freeMyDTMs;
begin
FreeDTM(Food);
FreeDTM(MoarFood);
end;

The addOnTerminate in the procedure that creates the DTMs will make sure that the DTMs are freed when the script terminates, so you don't need to worry about freeing them after you use them.

This way also has the advantage that you only have to think about the DTMs once, and you can use them anywhere else in your script.

NOTE: instead of having the DTMs be variables in each function, have them as global variables so they persist between functions.


It's probably best if I explain myself somewhat; I'm (trying) to make a script that eats (food) what it gets hit (blood). Every other method I looked up of how to eat was sketchy (switching between skill and inventory tab every second, etc).

Bare with me please, I'm very new to scripting and just learned DTM's about 30 minutes ago:

Made global variables at top of script:


var
Food,Blood, x, y: integer;

After 'DeclarePlayers' procedure I added what you said - and it compiles (when I was reading tutorials I kept getting a compiling error):



procedure freeMyDTMs;
begin
Food1:= DTMFromString('mlwAAAHicY2dgYOhnYmCYA8SLgXgWE4TfBaV5GSGYCYj/ANWyAGkBIBYB4unVgkARRqyYiwE3wK4DgqEAACT+BqY=');
Blood:= DTMFromString('mlwAAAHicY2dgYPgOxJ+A+AcQ/4PiP0D8GYiXAvEqIF4NpZcA8XwgXgjEB4C4npkZK2YGyuHCjHgwFAAAuMoPVg==');
end;


procedure loadMyDTMs;
begin
Food1:= DTMFromString('mlwAAAHicY2dgYOhnYmCYA8SLgXgWE4TfBaV5GSGYCYj/ANWyAGkBIBYB4unVgkARRqyYiwE3wK4DgqEAACT+BqY=');
Blood:= DTMFromString('mlwAAAHicY2dgYPgOxJ+A+AcQ/4PiP0D8GYiXAvEqIF4NpZcA8XwgXgjEB4C4npkZK2YGyuHCjHgwFAAAuMoPVg==');
addOnTerminate('freeMyDTMs');
end;



I'm guessing I'll need to add these procedures into my 'begin-end.' at the very end (I apologize, not sure what this is called).

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
loadMyDTMs;
LoginPlayer;
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('n');
repeat
mainLoop;
until(false);
freeMyDTMs;
end.
^ Is this OK?

@NKN, it didn't work for me sorry. Hope I didn't mess it up somehow.

Zace

2015-04-09 23:30:09

From: Polack

I'm guessing I'll need to add these procedures into my 'begin-end.' at the very end (I apologize, not sure what this is called).

@NKN, it didn't work for me sorry. Hope I didn't mess it up somehow.


You're correct.

Polack

2015-04-09 23:33:56

Would just like to add really quick that although my script is pretty bad, the eating does seem to be working quite well (definetely better then the other "methods.")
On a side note, can someone tell me what I need to do to read NPC talking (like a random event saying my name for example, or one of those guards saying "Stop," etc.)

fastler

2015-04-10 11:35:37

From: Polack
Would just like to add really quick that although my script is pretty bad, the eating does seem to be working quite well (definetely better then the other "methods.")
On a side note, can someone tell me what I need to do to read NPC talking (like a random event saying my name for example, or one of those guards saying "Stop," etc.)


Take a look at your earlier post and compare it with BMWxi's. Specifically the procedure "freeMyDTMs", that is where your DTMs will be freed.
The "addOnTerminate" sets the procedure "freeMyDTMs" to run once the script stops running. The call of "freeMyDTMs" at the end of your main begin-end is therefore unnecessary.

Polack

2015-04-10 12:13:04

This is my script…it works pretty well except I'm still having trouble treeing the DTM's! Very frustrating, I apologize to everyone for being so slow getting this right…


program Thief;
{$DEFINE SMART}
{$i srl-osr/srl.simba}


//SCRIPT EATS WHEN IT DETECTS HEALTH BAR ---> WORKS OK, (DOESN'T DIE OR SWITCH TABS EVERY MS AND YES IM THE ONLY PERSON THERE USUALLY)

var
Blood, Food, hX, hY, bX, bY: integer;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='Player';
Players[0].Pass :='Password';
Players[0].Nick :='Nickname';
Players[0].Active:=True;
end;

procedure freeMyDTMs;
begin
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
end;

procedure loadMyDTMs;
begin
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
addOnTerminate('freeMyDTMs');
end;

Procedure Eat;
begin
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
if FindDTM(Blood, hX, hY, MSX1, MSY1, MSX2, MSY2) then
begin
if FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(bX, bY, 1, 1);
Wait(250 + Random(250));
If(IsUpText('ebab')) Then
Wait(100 + Random(50));
Mouse(bX, bY, 0, 0, True);
wait(7000+ Random(250));
end else
begin
if not FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
Logout;
Writeln('Out of food');
TerminateScript;
end;
end;
end;
end;

Procedure Pickpocket;
Var
X, Y, Z: Integer;
begin
if FindObjCustom(X, Y, ['ickpocket', 'arrior'], [6601841, 9222602], 3) then
begin
mouse(X, Y, 0, 0, true);
while IsMoving do wait(Z);
end;
end;



Procedure mainLoop;
begin
if not LoggedIn then LoginPlayer else
begin
loadMyDTMs;
Eat;
Pickpocket;
freeMyDTMs;
end;
end;

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
repeat
mainLoop;
until(false);
end.

Polack

2015-04-10 22:24:10

Shameful bump :(.

Ian

2015-04-10 22:59:06

From: Polack
Shameful bump :(.


@ your previous post, you don't need to declare the DTMs in the procedure that you use them in anymore.

And you don't need to call freeMyDTMs;, simba will call it.

Polack

2015-04-11 00:25:43

From: BMWxi
@ your previous post, you don't need to declare the DTMs in the procedure that you use them in anymore.

And you don't need to call freeMyDTMs;, simba will call it.




Still getting

The following DTMs were not freed: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

(more DTM's not freed for more time running).

It's driving me insane.

bonsai

2015-04-11 04:12:41

From: Polack
Still getting

The following DTMs were not freed: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

(more DTM's not freed for more time running).

It's driving me insane.


That's because you're still calling dtmfromstring in your eat() function.

You already turned the string into the dtm key in your loadmydtms() function, you don't want to do it again and again.

Procedure Eat;
begin
if FindDTM(Blood, hX, hY, MSX1, MSY1, MSX2, MSY2) then
begin
if FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(bX, bY, 1, 1);
Wait(250 + Random(250));
If(IsUpText('ebab')) Then
Wait(100 + Random(50));
Mouse(bX, bY, 0, 0, True);
wait(7000+ Random(250));
end else
begin
if not FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
Logout;
Writeln('Out of food');
TerminateScript;
end;
end;
end;
end;

fastler

2015-04-12 14:09:22

Compare this with your script:
program Thief;
{$DEFINE SMART}
{$i srl-osr/srl.simba}


//SCRIPT EATS WHEN IT DETECTS HEALTH BAR ---> WORKS OK, (DOESN'T DIE OR SWITCH TABS EVERY MS AND YES IM THE ONLY PERSON THERE USUALLY)

var
Blood, Food, hX, hY, bX, bY: integer;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='Player';
Players[0].Pass :='Password';
Players[0].Nick :='Nickname';
Players[0].Active:=True;
end;

procedure freeMyDTMs;
begin//will free your DTMs
FreeDTM(Blood);
FreeDTM(Food);
end;

procedure loadMyDTMs;
begin//will load your DTMs
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
addOnTerminate('freeMyDTMs');//once the script ends it will run the mentioned procedure
end;

Procedure Eat;
begin//DTMs are already taken care of
if FindDTM(Blood, hX, hY, MSX1, MSY1, MSX2, MSY2) then
begin
if FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(bX, bY, 1, 1);
Wait(250 + Random(250));
If(IsUpText('ebab')) Then
Wait(100 + Random(50));
Mouse(bX, bY, 0, 0, True);
wait(7000+ Random(250));
end else
begin
if not FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
Logout;
Writeln('Out of food');
TerminateScript;
end;
end;
end;
end;

Procedure Pickpocket;
Var
X, Y, Z: Integer;
begin
if FindObjCustom(X, Y, ['ickpocket', 'arrior'], [6601841, 9222602], 3) then
begin
mouse(X, Y, 0, 0, true);
while IsMoving do wait(Z);
end;
end;



Procedure mainLoop;
begin
if not LoggedIn then LoginPlayer else
begin//DTMs are already taken care of
Eat;
Pickpocket;
end;
end;

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;//call this once, and you are good
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
repeat
mainLoop;
until(false);
end.

Polack

2015-04-13 15:40:03

From: fastler
Compare this with your script:
program Thief;
{$DEFINE SMART}
{$i srl-osr/srl.simba}


//SCRIPT EATS WHEN IT DETECTS HEALTH BAR ---> WORKS OK, (DOESN'T DIE OR SWITCH TABS EVERY MS AND YES IM THE ONLY PERSON THERE USUALLY)

var
Blood, Food, hX, hY, bX, bY: integer;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='Player';
Players[0].Pass :='Password';
Players[0].Nick :='Nickname';
Players[0].Active:=True;
end;

procedure freeMyDTMs;
begin//will free your DTMs
FreeDTM(Blood);
FreeDTM(Food);
end;

procedure loadMyDTMs;
begin//will load your DTMs
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
addOnTerminate('freeMyDTMs');//once the script ends it will run the mentioned procedure
end;

Procedure Eat;
begin//DTMs are already taken care of
if FindDTM(Blood, hX, hY, MSX1, MSY1, MSX2, MSY2) then
begin
if FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(bX, bY, 1, 1);
Wait(250 + Random(250));
If(IsUpText('ebab')) Then
Wait(100 + Random(50));
Mouse(bX, bY, 0, 0, True);
wait(7000+ Random(250));
end else
begin
if not FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
Logout;
Writeln('Out of food');
TerminateScript;
end;
end;
end;
end;

Procedure Pickpocket;
Var
X, Y, Z: Integer;
begin
if FindObjCustom(X, Y, ['ickpocket', 'arrior'], [6601841, 9222602], 3) then
begin
mouse(X, Y, 0, 0, true);
while IsMoving do wait(Z);
end;
end;



Procedure mainLoop;
begin
if not LoggedIn then LoginPlayer else
begin//DTMs are already taken care of
Eat;
Pickpocket;
end;
end;

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;//call this once, and you are good
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
repeat
mainLoop;
until(false);
end.


Hey, I apologize for the late replies guys, I had exams that took priority. My updated script was the exact same as yours, and what threw me off is that I still got this debug:


The following DTMs were not freed: [0, 1, 2, 3]

However, I just realized now testing it that the numbers don't seem to increase past 3 anymore (which is a big improvement). Will this still cause a memory leak, and if so, how significant are we talking about (I don't want to destroy my laptop, I'm not quite finished with it yet). If this problem is fixed, then I can probably (FIANLLY) run the script for extended periods of time and get some good XP lol.
Thanks again for all the help, I appreciate everyone's output.

Zace

2015-04-13 21:24:35

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;//call this once, and you are good
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
repeat
mainLoop;
until(false);
freeMyDTMs;//try freeing your DTMs at the bottom
end.

Polack

2015-04-13 22:05:40

From: Zace
begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;//call this once, and you are good
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
repeat
mainLoop;
until(false);
freeMyDTMs;//try freeing your DTMs at the bottom
end.


Nope, still get

The following DTMs were not freed: [0, 1, 2, 3]


Could it be because I'm manually stopping the script? I always press the red rectangle, but don't press the red circle.
https://villavu.com/forum/archive/index.php/t-77920.html


This is my code:


program Thief;
{$DEFINE SMART}
{$i srl-osr/srl.simba}

var
Blood, Food, hX, hY, bX, bY: integer;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='XX';
Players[0].Pass :='XX';
Players[0].Nick :='XX';
Players[0].Active:=True;
end;

procedure freeMyDTMs;
begin
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
end;

procedure loadMyDTMs;
begin
Blood:= DTMFromString('mggAAAHicY2NgYJBjZGBQh2JhKJYF4nCgXAgQR0BxCBQz/MeBcQBGHBgCAKBsCL8=');
Food:= DTMFromString('mrAAAAHic42BgYHBkYmBwA2IfIPaFsm2B2AyIbYD4EVDNTSC+zQBhvwDid0D8CogfAPG0aiGGnmIhBmdzBgZzHQaGRH9OhtYcPobD8yUZlnWIMXAB1eDDjAQwDAAAXVYRJg==');
addOnTerminate('freeMyDTMs');
end;

Procedure Eat;
begin
if FindDTM(Blood, hX, hY, MSX1, MSY1, MSX2, MSY2) then
begin
if FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(bX, bY, 1, 1);
Wait(250 + Random(250));
If(IsUpText('ebab')) Then
Wait(100 + Random(50));
Mouse(bX, bY, 0, 0, True);
wait(5500+ Random(250));
end else
begin
if not FindDTM(Food, bX, bY, MIX1, MIY1, MIX2, MIY2) then
begin
Logout;
Writeln('Out of food');
TerminateScript;
end;
end;
end;
end;

Procedure Pickpocket;
Var
X, Y, Z: Integer;
begin
begin
if FindObjCustom(X, Y, ['ickpocket', 'arrior['], [9901841, 1844602], 7) then
begin
mouse(X, Y, 0, 0, true);
while IsMoving do wait(Z);
end;
end;
end;



Procedure mainLoop;
begin
if not LoggedIn then LoginPlayer else
begin
Eat;
Pickpocket;
end;
end;


begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
addOnTerminate('freeMyDTMs');
repeat
mainLoop;
until(false);
TerminateScript;
freeMyDTMs;
end.


Zace

2015-04-13 22:50:55

Looks like you found your answer. Seems simba frees it but your script is not because you don't let it run till complete. Try just hitting stop once and wait a minute an see what happens.

Polack

2015-04-13 23:14:49

From: Zace
Looks like you found your answer. Seems simba frees it but your script is not because you don't let it run till complete. Try just hitting stop once and wait a minute an see what happens.


I ran the script with no food to make it terminate by itself, and I still got the same error:


Successfully executed.
The following DTMs were not freed: [0, 1, 2, 3]

This is the exact same error when I hit stop once and wait for it to terminate.

I believe that it is freeing the DTM's, but I would prefer not to take any unnecessary risks, so I'm hoping someone can confirm it's nothing.

fastler

2015-04-14 18:00:42

Yeah man. So close. Take caution what your "freeMyDTMs" does. It sets the DTMs once more.
Instead make it free the DTMs like so:
procedure freeMyDTMs;
begin//will free your DTMs
FreeDTM(Blood);
FreeDTM(Food);
end;

Once you have that, everything should work. Even without these things:
begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
addOnTerminate('freeMyDTMs');//remove this line - it gets called in "loadMyDTMs"
repeat
mainLoop;
until(false);
TerminateScript;//remove this line - this never get's called since you have an endless loop before, and it's redundant
freeMyDTMs;//remove this line - again, same as above, and above-above
end.

Polack

2015-04-14 19:40:40

From: fastler
Yeah man. So close. Take caution what your "freeMyDTMs" does. It sets the DTMs once more.
Instead make it free the DTMs like so:
procedure freeMyDTMs;
begin//will free your DTMs
FreeDTM(Blood);
FreeDTM(Food);
end;

Once you have that, everything should work. Even without these things:
begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
loadMyDTMs;
SetAngle(SRL_ANGLE_HIGH);
MakeCompass('e');
addOnTerminate('freeMyDTMs');//remove this line - it gets called in "loadMyDTMs"
repeat
mainLoop;
until(false);
TerminateScript;//remove this line - this never get's called since you have an endless loop before, and it's redundant
freeMyDTMs;//remove this line - again, same as above, and above-above
end.


Perfect, thank you. It's solved now; when I read your comment something clicked and I knew it had to be it!
Thanks to everyone else for their help and input.