Results 1 to 6 of 6

Thread: freeing DTM's

  1. #1
    Join Date
    May 2017
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default freeing DTM's

    What's up guys,

    I have a question about dtm's. Should they be called and freed every time u use one? Or is it all right if they get called before starting the mainloop and freed before the script stops?

  2. #2
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by Ivar View Post
    Or is it all right if they get called before starting the mainloop and freed before the script stops?
    Yes, you can do that.

  3. #3
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Quote Originally Posted by Ivar View Post
    What's up guys,

    I have a question about dtm's. Should they be called and freed every time u use one? Or is it all right if they get called before starting the mainloop and freed before the script stops?
    Good practice is to add this line after you loaded the DTMs, before your main loop:

    Simba Code:
    Addonterminate('StopScript');
    StopScript is the name of a procedure you create. It can be called anything really, so long as there is a procedure that corresponds with the name.

    This will fire every time the script is terminated. Anything you want to happen before the script stops, put it in this procedure.

    Here is an example extract from my NMZ script:

    Simba Code:
    procedure StopScript;
    var
      SessionXP: integer;
    begin
      freeDTM(Item_AbsorbPot.DTM);
      freeDTM(Item_RockCake.DTM);
      freeDTM(Item_AbsorbPotion.DTM);
      freeDTM(Item_RangedPot.DTM);
      freeDTM(Item_Overload.DTM);
      XPH := Round((CurrentSkillXp) / (GetTimeRunning / 3600000.0));
      SessionXP := GetSkillXP(SkilLToTrain) - StartingXP;
      AddReport('Script Terminated', True);
      AddReport('Elapsed time: ' + msToTime(GetTimeRunning, Time_Formal), True);
      AddReport('Experience gained: ' + IntToStr(SessionXP), True);
      AddReport('Experience gained per hour: ' +IntToStr(XPH), True);
     end;

    The benefit of this over simply putting FreeDTM at the bottom of your script, is that it will fire even if the script encounters an error, or is manually stopped.

  4. #4
    Join Date
    May 2017
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    Yes, you can do that.
    Quote Originally Posted by Dan the man View Post
    Good practice is to add this line after you loaded the DTMs, before your main loop:

    Simba Code:
    Addonterminate('StopScript');
    StopScript is the name of a procedure you create. It can be called anything really, so long as there is a procedure that corresponds with the name.

    This will fire every time the script is terminated. Anything you want to happen before the script stops, put it in this procedure.

    Here is an example extract from my NMZ script:

    Simba Code:
    procedure StopScript;
    var
      SessionXP: integer;
    begin
      freeDTM(Item_AbsorbPot.DTM);
      freeDTM(Item_RockCake.DTM);
      freeDTM(Item_AbsorbPotion.DTM);
      freeDTM(Item_RangedPot.DTM);
      freeDTM(Item_Overload.DTM);
      XPH := Round((CurrentSkillXp) / (GetTimeRunning / 3600000.0));
      SessionXP := GetSkillXP(SkilLToTrain) - StartingXP;
      AddReport('Script Terminated', True);
      AddReport('Elapsed time: ' + msToTime(GetTimeRunning, Time_Formal), True);
      AddReport('Experience gained: ' + IntToStr(SessionXP), True);
      AddReport('Experience gained per hour: ' +IntToStr(XPH), True);
     end;

    The benefit of this over simply putting FreeDTM at the bottom of your script, is that it will fire even if the script encounters an error, or is manually stopped.
    And I won't have to worry about memory leaks? I read somewhere that that can make stop scripts.
    I will definitely use the addOnTerminate, tyvm for explaining it thoroughly.

  5. #5
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Yes, even so, Simba still frees DTMs + Bitmaps on termination unless interrupted.

  6. #6
    Join Date
    May 2017
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    Yes, even so, Simba still frees DTMs + Bitmaps on termination unless interrupted.
    Big thanks for helping

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
  •