SRL Archive - OSR Help

Exception in Script: The given DTM Index doesn't exist


Atheos

2012-01-28 16:46:05

I've been lurking around the scripting tutorials for some days, and decided to try to make my own script. I have a problem though, i get this DTM error, which i could not find a solution for. Have been searching some around, and found tons of people having the same problem, but strangely no solution (might be me not looking good enough).

Anyway, what error i get is this:
Exception in Script: The given DTM Index[0] doesn't exist
The following DTMs were not freed: [1]

The problem occurs in the below function, in the first FindDTM, between WriteLn('called');, and WriteLn('called2');. It seems that way to me at least :p


  function CraftAndExit: boolean;
var
walksDTM, clickDTM, x, y, i: integer;
aFound: extended;
begin
walksDTM := DTMFromString('mrAAAAHic42BgYKhlYmBwgOJJQLwRiMOBOB2INwGxJ1' +
'CNHxDbAXETEHtB6RYgLgXi/EwlBvkofhTcVuvN0FTlCcZyQDW8ODAHEDMSwDAAAC/WDlM=');
wait(700 + random(90));
WriteLn('called');
if FindDTMRotated(walksDTM, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
begin
WriteLn('called2');
mouse(x, y, 1, 1, true);
FFlag(2);
clickDTM := DTMFromString('mlwAAAHicY2dgYOAEYiEg5mGAACYgFgBiPijmhYqB' +
'gBwQqwGxIhAnJsaAcWhQGENQQAhDZFgUQ3x8FENychwDK1AeF2bEg6EAAKs3CG8=');
if FindDTM(clickDTM, x, y, MSX1, MSY1, MSX2, MSY2) then
begin
WriteLn('called3');
InvMouse(2, 1);
wait(30 + random(50));
mouse(x, y, 10, 10, true);
FreeDTM(walksDTM);
FreeDTM(clickDTM);
Result := true;
Exit;
end;
end;
FreeDTM(walksDTM);
FreeDTM(clickDTM);
end;

It would not hurt if i could get some suggestions for improvements in the function otherwise as well. Thanks in advance :)

EDIT:
Stupid me managed to free 'clickDTM', even in the event it was not called, had to get some help at IRC to realise it :p

Chris

2012-01-28 16:54:22

You get that error because you are trying to free a DTM while it has already been freed, try deleting all "freeDTM();"s except the last two :)

Atheos

2012-01-28 16:57:56

Ah, forgot to add and end else and return false after the first Exit;, i see now.
Thanks! :)

EDIT:
It seems to be something else, or i am just doing something wrong. This is the function now:

  function CraftAndExit: boolean;
var
walksDTM, clickDTM, x, y, i: integer;
aFound: extended;
begin
if not LoggedIn then
Exit;
walksDTM := DTMFromString('mrAAAAHic42BgYKhlYmBwgOJJQLwRiMOBOB2INwGxJ1' +
'CNHxDbAXETEHtB6RYgLgXi/EwlBvkofhTcVuvN0FTlCcZyQDW8ODAHEDMSwDAAAC/WDlM=');
wait(700 + random(90));
WriteLn('called');
if FindDTMRotated(walksDTM, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
begin
WriteLn('called2');
mouse(x, y, 1, 1, true);
FFlag(2);
clickDTM := DTMFromString('mlwAAAHicY2dgYOAEYiEg5mGAACYgFgBiPijmhYqB' +
'gBwQqwGxIhAnJsaAcWhQGENQQAhDZFgUQ3x8FENychwDK1AeF2bEg6EAAKs3CG8=');
if FindDTM(clickDTM, x, y, MSX1, MSY1, MSX2, MSY2) then
begin
WriteLn('called3');
InvMouse(2, 1);
wait(30 + random(50));
mouse(x, y, 10, 10, true);
{ FreeDTM(walksDTM);
FreeDTM(clickDTM); }
Result := true;
Exit;
end else
begin
{ FreeDTM(walksDTM);
FreeDTM(clickDTM); }
Result := false;
Exit;
end;
end else
begin
FreeDTM(walksDTM);
FreeDTM(clickDTM);
Result := false;
end;
end;

I commented out all except the last instances of FreeDTM, and i still get the error :confused:
Other than that i can't see how it would run through more than one instance of them anyway, if i remember correctly Exit; exits the entire funtion? If it is any help, it still gets the error at the same line as mentioned in my first post.