# SDatabase

## Index

### Functions Index

| Function                                                                                          |
| ------------------------------------------------------------------------------------------------- |
| void [**GetRegionValue** ](#getregionvalue)(string key, Closure onResult)                         |
| void [**SetRegionValue** ](#setregionvalue)(string key, string value, Closure onSave)             |
| void [**GetPlayerValue** ](#getplayervalue)(int player, string key, Closure onResult)             |
| void [**SetPlayerValue** ](#setplayervalue)(int player, string key, string value, Closure onSave) |

## Functions

### GetRegionValue

void **GetRegionValue** (string key, Closure onResult)

*Get a value stored in the region database. (this does not access the same database as the SPersistence class)*

<table><thead><tr><th width="157.92824192721685">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>key</td><td>string</td><td>The "key" to access the record from the region database.</td></tr><tr><td>onResult</td><td>Closure</td><td>The name of the function which will be called once the results are ready.<br>This function will be called with a string parameter containing the requested value. onResult(value)</td></tr></tbody></table>

{% tabs %}
{% tab title="Lua" %}

```lua
function onResult(value)
yourValue = value
end

Space.Database.GetRegionValue("testKey", onResult)
```

{% endtab %}
{% endtabs %}

### SetRegionValue

void **SetRegionValue** (string key, string value, Closure onSave)

*Store a "value" in the region database. (this does not access the same database as the SPersistence class)*

| Parameter | Type    | Description                                                                                            |
| --------- | ------- | ------------------------------------------------------------------------------------------------------ |
| key       | string  | The "key" to access the record from the region database.                                               |
| value     | string  | The "value" that will be stored in the region database.                                                |
| onSave    | Closure | The name of the function which will be called when the "value" has been stored in the region database. |

{% tabs %}
{% tab title="Lua" %}

```lua
function onSave()
--
end

Space.Database.SetRegionValue("testKey", "testValue", onSave)
```

{% endtab %}
{% endtabs %}

### GetPlayerValue

void **GetPlayerValue** (int player, string key, Closure onResult)

*Get a value stored in a player database. (this does not access the same database as the SPersistence class)*

| Parameter | Type    | Description                                                                                                                                                                              |
| --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| player    | int     | The ID of the player's database in whose record we will access.                                                                                                                          |
| key       | string  | The "key" to access the record from the region database.                                                                                                                                 |
| onResult  | Closure | <p>The name of the function which will be called once the results are ready.<br>This function will be called with a string parameter containing the requested value. onResult(value)</p> |

{% tabs %}
{% tab title="Lua" %}

```lua
function onResult(value)
yourValue = value
end

Space.Database.GetPlayerValue(aPlayerID,"testKey",onResult)
```

{% endtab %}
{% endtabs %}

### SetPlayerValue

void **SetPlayerValue** (int player, string key, string value, Closure onSave)

*Store a "value" in a player database. (this does not access the same database as the SPersistence class). (this does not access the same database as the SPersistence class)*

| Parameter | Type    | Description                                                                                            |
| --------- | ------- | ------------------------------------------------------------------------------------------------------ |
| player    | int     | The ID of the player's database in whose record we will access.                                        |
| key       | string  | The "key" to access the record from the region database.                                               |
| onSave    | Closure | The name of the function which will be called when the "value" has been stored in the player database. |

{% tabs %}
{% tab title="Lua" %}

```lua
function onSave()
--
end

Space.Database.SetPlayerValue(aPlayerID,"testKey", "testValue",onSave)
```

{% endtab %}
{% endtabs %}
