PDA

View Full Version : Why is time so hard to reset



hackingislol133
05-27-2014, 09:36 AM
I'm trying to start a timer when familiar timer reaches the 2:30 (1650000ms) resummon threshold when I realized that the timer for isn't resetting after the resummon. I stared at it for a few minutes and are completely stumped at what I'm doing wrong. I tested TTimeMarker in a test script and it produced the same result of not resetting the timer.


procedure ResummonFamiliar;
var
STimer: TTimeMarker;
x, y, SummonDTM: Integer;
begin
STimer.start;
if (STimer.getTime() <= 1650000) then
begin
SummonDTM := DTMFromString('mggAAAHicY2NgYPjMzMDwHYj/Qem7ULyCiYFhJhAvAeINQDwPiNcA8bHZzAzCulYMsamZDGYu3m A2p7IRgyTQLGyYEQeGAABbuA7f');
wait(random(300,600));
if findDTM(SummonDTM, x, y, MainScreen.GetBounds) then
begin
mouse(x, y, 3, 3, MOUSE_MOVE);
wait(randomrange(250,500));
fastClick(MOUSE_LEFT);
if chooseOption.select(['ene', 'amili']) then
begin
writeLn('Resummoning');
wait(5000 + randomrange(1000,2000));
STimer.reset;
writeLn(STimer.getTime);
end
end
end
end;

I don't understand what I'm doing wrong here.

bonsai
05-27-2014, 11:40 AM
If you declare your timer within the procedure it will be "created fresh" each time the procedure is called. If you want it to last outside of the procedure call you need to make it a global.

Your "if timer <= 1650000" should probably be returning something like 1ms all the time.

You should have a call to freeDTM at the bottom of the procedure. Any time you create a DTM you should also free it.

DemiseScythe
05-27-2014, 04:00 PM
Do it the old school way, GetSystemTime and Cardinal variables. Works perfectly every time for me.

masterBB
05-27-2014, 04:53 PM
A small bug in TTimeMarker has been fixed. It would still appear to be running if you used GetTime without calling start or stop. https://github.com/SRL/SRL-6/pull/111

Though also, your code still wouldn't work. I see one logic flaw and one memory leak.

The logic flaw is easy to spot and was also mentioned by bonsai. If you look at the flow of this function:


-> Starts Timer

-> If the timer has been running for less 1650000ms Then
//This is the logic flaw. You JUST started the timer.

-> Other Code

-> End if


I think you wanted to do:


-> Starts Timer

-> While the timer has been running for less 1650000ms Then
//The following code will be repeated till the timer has been running 1650 seconds

-> Other Code

-> End While


This would look like this:


procedure ResummonFamiliar;
var
STimer: TTimeMarker;
x, y, SummonDTM: Integer;
begin
STimer.start;
while (STimer.getTime() <= 1650000) then
begin
SummonDTM := DTMFromString('mggAAAHicY2NgYPjMzMDwHYj/Qem7ULyCiYFhJhAvAeINQDwPiNcA8bHZzAzCulYMsamZDGYu3m A2p7IRgyTQLGyYEQeGAABbuA7f');
wait(random(300, 600));
if findDTM(SummonDTM, x, y, MainScreen.GetBounds) then
begin
mouse(x, y, 3, 3, MOUSE_MOVE);
wait(randomrange(250, 500));
fastClick(MOUSE_LEFT);
if chooseOption.select(['ene', 'amili']) then
begin
writeLn('Resummoning');
wait(5000 + randomrange(1000, 2000));
STimer.reset;
writeLn(STimer.getTime);
end;
end;
end;
end;

The Memory issue needs to be addressed next. Everytime you call DTMFromString you load a new DTM into the memory. This will eventually fill your computer its entire memory. It is adviced for beginners to load them at the beginning of the script and not in functions or loops till you fully understand the flow of a script.

A fix would be to load it once at the beginning of the function and free it at the end. I still advice to place it before your mainloop.


procedure ResummonFamiliar;
var
STimer: TTimeMarker;
x, y, SummonDTM: Integer;
begin
SummonDTM := DTMFromString('mggAAAHicY2NgYPjMzMDwHYj/Qem7ULyCiYFhJhAvAeINQDwPiNcA8bHZzAzCulYMsamZDGYu3m A2p7IRgyTQLGyYEQeGAABbuA7f');

STimer.start;
while (STimer.getTime() <= 1650000) then
begin
wait(random(300, 600));
if findDTM(SummonDTM, x, y, MainScreen.GetBounds) then
begin
mouse(x, y, 3, 3, MOUSE_MOVE);
wait(randomrange(250, 500));
fastClick(MOUSE_LEFT);
if chooseOption.select(['ene', 'amili']) then
begin
writeLn('Resummoning');
wait(5000 + randomrange(1000, 2000));
STimer.reset;
writeLn(STimer.getTime);
end;
end;
end;

FreeDTM(SummonDTM );
end;

Not related to the bug still showing the time running. I named TTimeMarker TStopWatch when I wrote it. All the functions are made to reflect that. Reset does the same thing as pressing reset on the stopWatch. It doesn't actually restart the stopwatch, just resets it to 0. It needs to be started again after that.

procedure ResummonFamiliar;
var
STimer: TTimeMarker;
x, y, SummonDTM: Integer;
begin
SummonDTM := DTMFromString('mggAAAHicY2NgYPjMzMDwHYj/Qem7ULyCiYFhJhAvAeINQDwPiNcA8bHZzAzCulYMsamZDGYu3m A2p7IRgyTQLGyYEQeGAABbuA7f');

STimer.start;
while (STimer.getTime() <= 1650000) then
begin
wait(random(300, 600));
if findDTM(SummonDTM, x, y, MainScreen.GetBounds) then
begin
mouse(x, y, 3, 3, MOUSE_MOVE);
wait(randomrange(250, 500));
fastClick(MOUSE_LEFT);
if chooseOption.select(['ene', 'amili']) then
begin
writeLn('Resummoning');
wait(5000 + randomrange(1000, 2000));
STimer.reset();
STimer.start();
end;
end;
end;

FreeDTM(SummonDTM );
end;

Good luck scripting!

hackingislol133
05-27-2014, 08:21 PM
Yea, I see the logic error now. The operator is supposed to be >=. Much appreciated :)

Regarding your advice on freeing DTMs at the end of every procedure to decrease the memory footprint.

Would it also be safe to assume that I should also free ATPAs at the end of every procedure as well?

masterBB
05-27-2014, 09:38 PM
Yea, I see the logic error now. The operator is supposed to be >=. Much appreciated :)

Regarding your advice on freeing DTMs at the end of every procedure to decrease the memory footprint.

Would it also be safe to assume that I should also free ATPAs at the end of every procedure as well?

Only bitmaps and dtms.

You recognize them if the type is a Integer instead of the type you would expect(TDTM and TMufasaBitmap)

Olly
05-28-2014, 12:32 AM
Heh, The amount of dtm's you would have to create to notice a memory difference is insane... I would just globally load em :p

hackingislol133
05-29-2014, 08:11 PM
I'm looking at my memory footprint and it seems that it gradually increases, while loading a DTM I'm guessing.

I've freed them in every procedure they need to be freed at but the memory usage still increases.

edit: nevermind, the cause of the gradual increase in memory is the loading of new areas of the map which adds up with each mainloop run. I'm guessing this is an unavoidable issue.