PDA

View Full Version : How to reset a local variable in a loop?



MasterXehanort
02-12-2015, 04:55 AM
Hello everyone. I'm having trouble trying to figure out how to reset the value of a local variable (in this case, an integer). The context is as such: The portion of the script I'm trying to fix is making unfinished potions. In dungeoneering, the wait time between each potion is ~3 seconds. The wait time can be reduced if you re-mix the vial of water with the herb. This has the possibilty to boost xp/hr drastically (waiting 1 second/potion vs 3 seconds/potion). I've looked through some pascal tutorials and found a few functions to reset/release memory, but the variable type stored is an integer (where the "freeMem();" call only free's a pointer variable).

Here's the code I have so far:


procedure mixUnfinishedPotions();
var
x, y, x2, y2: integer;
begin

while isWaterVialVisible do //The isWaterVialVisible is a function that returns "True" if a vial of water is in the tabBackPack
//freemem(x2); //Here I am trying to free the coordinates (x2, y2) because we want to store new coordinates for another vial of water, as the initial one is no longer present.
//freemem(y2); //Initially, freeing a nonstored variable should do nothing, but after the script processes through the while loop at least once, I want to release the (x2, y2) coordinate to store a new one.

begin
findDTM(cleanDTM, x, y, tabBackPack.getBounds()); //Here we are finding the clean herb DTM and storing the coordinates as (x, y)
mouse(x, y, 3, 3, MOUSE_MOVE); //Here we move the mouse to (x, y)
if isMouseOverText(['lean']) then //If the uptext correctly identifies that the mouse is over the clean herb, we click it
begin
fastClick(MOUSE_LEFT);

findDTM(waterVialDTM, x2, y2, tabBackPack.getBounds()); //Here we are finding the vial of water DTM and storing the coordinates as (x2, y2)
mouse(x2, y2, 3, 3, MOUSE_MOVE); //Move the mouse to (x2, y2)
if isMouseOverText(['ial', 'ater']) then //If the uptext shows that we can mix the two, click.
begin
fastClick(MOUSE_LEFT);
wait(GaussRangeInt(850, 1000));
pressKey(32);
wait(GaussRangeInt(800, 1000));
end;
end;

end;
end;

The Mayor; KeepBotting; Any advice you two can give me?

riwu
02-12-2015, 05:06 AM
U cant and don't have to "free" the integer variables, they can simply be reused and assigned different values automatically. If u want to reset their value to 0 for some purposes, simply assign them to 0 (x2:=0)

MasterXehanort
02-12-2015, 05:11 AM
U cant and don't have to "free" the integer variables, they can simply be reused and assigned different values automatically. If u want to reset their value to 0 for some purposes, simply assign them to 0 (x2:=0)

Hmm, when I let it run as is, the mouse correctly clicks the herb, but hovers over the spot where the initial vial of water was instead of finding the new ones. The DTM chosen is highlighting all the vials of water as being found.

riwu
02-12-2015, 05:30 AM
Try adding writeln(finddtm(..)) and writeln([x2, y2])

MasterXehanort
02-12-2015, 06:59 AM
Try adding writeln(finddtm(..)) and writeln([x2, y2])

Adding that and several other writeLn's to see what's messing up.

Also, is tabBackPack.countDTM dependent on time? For example, if you wait x amount of time before calling tabBackPack.countDTM, would that change the return value if instead you waited 0 amount of time?

riwu
02-12-2015, 07:29 AM
not too sure what u mean, if the input (smart canvas) changes during the wait then naturally the result will be different?

cosmasjdz
02-12-2015, 07:31 AM
Hmm, when I let it run as is, the mouse correctly clicks the herb, but hovers over the spot where the initial vial of water was instead of finding the new ones. The DTM chosen is highlighting all the vials of water as being found.

probably your last wait 800-1000 ms isnt enough for vial to change state or your filled vial is missinterpreted as vial with water.

Also in this state you dont need to change variable values manually as finddtm functions overwrites them automatically. Setting to 0 like x2:=0 is redundant.

Also to deal with weird behaviour of script usually is needed to writeln(what is now going ) every step. And look for unlogical decisions by script done, then search why it is.

The Mayor
02-12-2015, 09:47 AM
What about something like


procedure mixUnfinishedPotions();
begin

repeat

if not tabBackpack.clickDTM(waterVialDTM, MOUSE_LEFT, 'ial', 300, False) then
break()
else if tabBackpack.clickDTM(cleanDTM, MOUSE_LEFT, 'lean', 300, False) then
begin
pressKey(32);
tabBackpack.waitForShift(1200);
end;

until false;

end;