Results 1 to 8 of 8

Thread: How to reset a local variable in a loop?

  1. #1
    Join Date
    Apr 2012
    Location
    Gielinor
    Posts
    231
    Mentioned
    4 Post(s)
    Quoted
    33 Post(s)

    Default How to reset a local variable in a loop?

    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:

    Simba Code:
    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?

  2. #2
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    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)

  3. #3
    Join Date
    Apr 2012
    Location
    Gielinor
    Posts
    231
    Mentioned
    4 Post(s)
    Quoted
    33 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    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.

  4. #4
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Try adding writeln(finddtm(..)) and writeln([x2, y2])

  5. #5
    Join Date
    Apr 2012
    Location
    Gielinor
    Posts
    231
    Mentioned
    4 Post(s)
    Quoted
    33 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    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?

  6. #6
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    not too sure what u mean, if the input (smart canvas) changes during the wait then naturally the result will be different?

  7. #7
    Join Date
    Jun 2014
    Location
    Lithuania
    Posts
    475
    Mentioned
    27 Post(s)
    Quoted
    200 Post(s)

    Default

    Quote Originally Posted by MasterXehanort View Post
    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.

  8. #8
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    What about something like

    Simba Code:
    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;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •