---
name: "createHashMapObject"
type: command
status: ok
groups: ["HashMap"]
arma3_since: "2.14"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/createHashMapObject
revid: 377952
updated: 2026-01-15T10:26:48Z
---

# createHashMapObject

*Command · HashMap · Arma 3 v2.14*

## Description

Create a [HashMap](../topics/HashMap.md) with an [Object-Oriented Programming](https://en.wikipedia.org/wiki/Object-oriented_programming) behaviour.

Inside a object, Methods (if they are called correctly, either by engine or via [call#Syntax 3](../commands/call.md#syntax-3)) will have the objects instance inside the `_self` variable.

The Destructor ("#delete" method) will be executed when the last reference to the objects variable gets deleted. (Except when the mission is ended and all variables are deleted at once)

Inheritance: HashMap objects support a simple form of Inheritance.

It behaves similar to the [merge](../commands/merge.md) command with overwriteExisting enabled. Sub-class methods and properties with same name, overwrite their Base-class values.

Constructor/Destructor/Clone methods will be merged together and executed in sequence.

Flags entry will use overwrite behaviour.

## Syntax

```sqf
createHashMapObject [classDefinition, constructorArguments]
```

**Parameters:**

- `classDefinition`: [HashMap](../topics/HashMap.md) or [Array](../topics/Array.md) of [Array](../topics/Array.md)s, format [name, value]:
  *name* can be anything like any other [HashMap](../topics/HashMap.md), but it must be a [String](../topics/String.md) for it to be used like an OOP object method (see [call#Syntax 3](../commands/call.md#syntax-3)).

  Some special values, starting with `1.`, are reserved and expect a specific *value* type (they are all optional):
  - `"#create"`: [Code](../topics/Code.md) - this is the hashmap object's constructor
  - `"#clone"`: [Code](../topics/Code.md) - this is code happening when cloning is done on this hashmap object
  - `"#delete"`: [Code](../topics/Code.md) - this is the hashmap object's destructor. It will always be executed inside [missionNamespace](../commands/missionNamespace.md).
  - `"#str"`: [Code](../topics/Code.md) - code that is used to evaluate what is displayed when the [str](../commands/str.md) function is called on the object - **must** return [String](../topics/String.md)
  - `"#flags"`: [Array](../topics/Array.md) of [String](../topics/String.md)s - case-*in*sensitive flags regarding this hashmap object
    - "noCopy": forbids copying, `+_hashMapObject` will throw an error
    - "sealed": prevents from adding and removing any keys - key values can still be edited
    - "unscheduled": all methods (including `1. clone` and `1. create`) will be executed in [unscheduled environment](../topics/Scheduler.md#unscheduled-environment)
  - `"#base"`: [Array](../topics/Array.md) or [HashMap](../topics/HashMap.md) - declaration of base class for inheritance
  - `"#type"`: [String](../topics/String.md) - can be used to give a object a "type name", on inheritance types will be merged into an [Array](../topics/Array.md)
  Note that all entries beginning with `1.` are reserved, the engine might use these internally without their use being documented.
- `constructorArguments`: [Anything](../topics/Anything.md) - (Optional, default [Nothing](../topics/Nothing.md)) passed as `_this` argument to the "#create" method.

**Returns:** [HashMap](../topics/HashMap.md)

## Examples

### Example 1

```sqf
private _declaration = [
    ["#flags", ["sealed"]],
    ["#create", { hint "Hello!" }],
    ["#clone", { hint "We were copied!" }],
    ["#delete", { hint "Goodbye" }],
    ["#str", { "My HashMap Object" }],
    ["Method", { hint "Method has been called" }]
];

private _hashMapObject = createHashMapObject [_declaration];    // hints "Hello!"
_hashMapObject call ["Method"];                                    // hints "Method has been called"
hint str _hashMapObject;                                        // hints "My HashMap Object"
private _shallowCopy = _hashMapObject;                            // no hint
private _deepCopy = +_hashMapObject;                            // hints "We were copied!"
// at the end of the scope, _hashMapObject is deleted and hints "Goodbye"
```

### Example 2

Inheritance constructor/destructor/copy orderings: 

```sqf
private _animalDeclaration = [
    ["#type", "IAnimal"],
    ["#create", { systemChat "Animal Init" }],
    ["#clone", { systemChat "Animal Copied" }],
    ["#delete", { systemChat "Animal Bye" }]
];

private _pigDeclaration = [
    ["#base", _animalDeclaration],
    ["#type", "Pig"],
    ["#create", { systemChat "Pig Init" }],
    ["#clone", { systemChat "Pig Copied" }],
    ["#delete", { systemChat "Pig Bye" }]
];

private _smolPigDeclaration = [
    ["#base", _pigDeclaration],
    ["#type", "SmolPig"],
    ["#create", { systemChat "SmolPig Init" }],
    ["#clone", { systemChat "Smol Copied" }],
    ["#delete", { systemChat "Smol Bye" }]
];

private _smolPigInstance = createHashMapObject [_smolPigDeclaration]; // prints "Animal Init", "Pig Init", "SmolPig Init"
private _copy = +_smolPigInstance; // prints "Animal Copied", "Pig Copied", "SmolPig Copied"
_copy = nil; // prints "SmolPig Bye", "Pig Bye", "Animal Bye"
```

### Example 3

Inheritance type checking:

```sqf
private _animalDeclaration = [
    ["#type", "IAnimal"],
    ["FurType", { "None" }] // default implementation
];

private _pigDeclaration = [
    ["#base", _animalDeclaration],
    ["#type", "Pig"],
    ["FurType", { "Bristles" }] // override the base class method
];

private _catDeclaration = [
    ["#base", _animalDeclaration],
    ["#type", "Cat"],
    ["FurType", { "Hair" }] // override the base class method
];

private _instance = createHashMapObject [selectRandom [_pigDeclaration, _catDeclaration]];

if ("IAnimal" in (_instance get "#type")) then // check if a object instance is or inherits from a specific type
{
    _instance call ["FurType"]; // now that we know it implements IAnimal, we know that "FurType" method will be present
};
```

### Example 4

Destructor: 

```sqf
private _temporaryVehicle = [
    ["#create", {
        params ["_vehicleType", "_vehiclePos", "_lifetimeSeconds"]; // handle constructor arguments
        private _newVehicle = _vehicleType createVehicle _vehiclePos;
        _self set ["MyVehicle", _newVehicle]; // Store the vehicle inside the object for later

        // because _self is passed as parameter, it will be referenced by the spawned script until it ends.
        [_lifetimeSeconds, _self] spawn { params ["_lifetimeSeconds", "_self"]; sleep _lifetimeSeconds; };
    }],
    ["#delete", {
        deleteVehicle (_self get "MyVehicle"); // delete the vehicle when we go away
    }],
    ["MyVehicle", objNull] // placeholder, this is not needed
];

// create a temporary RoadCone, at player position, that will delete itself after 5 seconds.
createHashMapObject [_temporaryVehicle, ["RoadCone_F", getPos player, 5]];
```

## See also

[call](../commands/call.md) · [createHashMap](../commands/createHashMap.md)

<sub>Source: [BI Community Wiki — createHashMapObject](https://community.bistudio.com/wiki/createHashMapObject) (revision 377952).</sub>
