Difference between revisions of "Constructor"
(new page) |
(No difference)
|
Revision as of 14:44, 12 August 2013
Description
Constructors are used to allocate memory for a new object/class/variable etc.
It's important to remember to free previously allocated memory by using Destructors
Usage
There are some user constructable classes in Script Core 3, for example TNewPlayer and TNewMapObject.
Below example shows the usage of TNewMapObject.Create, which is this classes constructor.
procedure SpawnMedkit(posx,posy: single);
var temp: TNewMapObject;
begin
temp := TNewMapObject.Create;
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!
end;
procedure MyOnSpeak(p: TActivePlayer; Text: string);
begin
if lowercase(Text) = 'Medic!' then
SpawnMedkit(p.X,p.Y);
end;