SRL Archive - OSR Help

DTM as Constant


astoria1112000

2011-12-01 03:49:35

Can I use DTM as a constant

YoHoJo

2011-12-01 03:50:02

Hmm no clue, but what do you mean, why would you want to do that for?

astoria1112000

2011-12-01 03:54:02

I want to use DTM in my main block as well as some function where do I initialize it

KingKong

2011-12-01 04:00:12

From: astoria1112000
Can I use DTM as a constant


From: astoria1112000
I want to use DTM in my main block as well as some function where do I initialize it


You mean that you only want to initialize it once so that you can use it everywhere? Then declare it as a global variable. Eg:

program new;
//include srl here

var
dtmstring: string; //<<< global variable when declared outside other functions/procs
DTM: Integer; //<<< global variable when declared outside other functions/procs

procedure blahbla;
begin
end;

procedure somemoreblaaaa;
begin
end;

procedure MainLoop;
begin
DTM := DTMFromString(dtmstring);//initialize dtm at start of script once!
//dtmstring is the funny string you get: 'CBVnaldsfghiolasndg+asdklans564351'
blahbla;
somemoreblaaaa;
end;

begin
//SetupSRL;
MainLoop;
end.

astoria1112000

2011-12-01 04:13:20

wait if it doesnt work now, i will post my code here

Look at this and tell me if its fine

While(True) do
Begin

DTM := DTMFromString('……');
if FindDTM(DTM, x, y,…..) then
…..

FreeDTM(DTM);
End;

YoHoJo

2011-12-01 04:17:41

You want to put the BEFORE the while loop
like this
DTM := DTMFromString('……');
While (True) Do

That way it's only loaded once! Not over and over :D

astoria1112000

2011-12-01 04:20:52

What does FreeDTM(DTM) do… Do i need to reinitialize the DTM to use it again

KingKong

2011-12-01 04:28:25

From: astoria1112000
What does FreeDTM(DTM) do… Do i need to reinitialize the DTM to use it again


FreeDTM reallocates/removes the memory that was used to store the DTM so that your script uses less RAM(or cpu?). And yes if you freedtm you have to do dtm := dtmfromstring() again if you want to use it.

Note: The less times you load/unload the better it is in terms of memory management.

astoria1112000

2011-12-01 04:32:55

So how can I do it if I need to use DTM inside my WHILE LOOP without loading and unloading it inside my loop

YoHoJo

2011-12-01 04:35:31

LoadDTM
While (Ture) Do
Begin
Stuff
If FindDTM Then
Stuff
End;
FreeDTM;

Like that

KingKong

2011-12-01 04:36:32

From: astoria1112000
So how can I do it if I need to use DTM inside my WHILE LOOP without loading and unloading it inside my loop


load it before starting the loop and unload it after the loop.

E: Damn ninja'd by YoHoJo

astoria1112000

2011-12-01 04:40:18

I terminate my script manually so is there a way to FreeDTM when I stop the script (Clicking RED STOP button)

KingKong

2011-12-01 04:44:50

From: astoria1112000
I terminate my script manually so is there a way to FreeDTM when I stop the script (Clicking RED STOP button)


I think its automatically freed. But you can do this:

AddOnTerminate('name_of_procedure_or_function');


put the freedtm in a procedure and call addonterminate at the start of the script. That way the dtm will be freed for sure.

Note: You have to include srl to use addonterminate.

astoria1112000

2011-12-01 05:06:06

Thank you guys for your help, Script 90% done