Destructor

From Soldat Community Wiki
Revision as of 15:46, 12 August 2013 by Mighty (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

Destructors are used to free memory previously allocated with Constructor.

Usage

There are some user constructable classes in Script Core 3, for example TNewPlayer and TNewMapObject.
Below example shows the usage of TNewMapObject.Free, which is this classes destructor.

procedure SpawnMedkit(posx,posy: single);
var temp: TNewMapObject;
begin
  temp := TNewMapObject.Create; // constructor
  temp.X := posx;
  temp.Y := posy;
  temp.Style := 16;
  Map.AddObject(temp); // we could also save object's ID (newly spawned medkit)\
  temp.Free; // IMPORTANT! destructor
end;

procedure MyOnSpeak(p: TActivePlayer; Text: string);
begin
  if lowercase(Text) = 'Medic!' then
    SpawnMedkit(p.X,p.Y);
end;