# Grid Memory

## ⚙️Installation

1. Download `vise_grid_memory_game` resource from Cfx.re Keymaster
2. Extract `vise_grid_memory_game` into your server's resources directory
3. Add `ensure vise_grid_memory_game` to your `resources.cfg`

## 🕹️ Starting the Game

You can either **start the game through your own scripts** or use **the test command.**

**✅ Starting through your own scripts:**

```lua
local result = exports.vise_grid_memory_game:start()

print('game ended with result:', result)
```

**✅ Using the test command:**

Type command `/test_vise_grid_memory_game` in-game.

{% tabs %}
{% tab title="Video preview" %}
{% embed url="<https://youtu.be/VuuLLhcNqk4?t=72>" %}
Game can be seen at 1:12-1:35
{% endembed %}
{% endtab %}

{% tab title="Image preview" %}

<div><figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2F5eUPzlI2W9aSfOsTDbTG%2Fvise_grid_memory_main.png?alt=media&#x26;token=1f189547-6f79-46e4-a674-d5be01827e8f" alt=""><figcaption><p>Game main screen</p></figcaption></figure> <figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2Fd5azcdH8m2cdJK1CjrlB%2Fvise_grid_memory_win.png?alt=media&#x26;token=eb1c7543-f824-4bf3-9de8-de52bc26e195" alt=""><figcaption><p>Success screen</p></figcaption></figure> <figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2Fk8SmisEwd2PiGVyuJ6rv%2Fvise_grid_memory_loss.png?alt=media&#x26;token=97849c11-2f1d-4898-b3f6-128b17511ca4" alt=""><figcaption><p>Failure screen</p></figcaption></figure></div>
{% endtab %}
{% endtabs %}

🔄 **Result (return value)**

The `start()` function will return `true` if the player finishes the game, or `false` if they fail or run out of time.\
\
If you're using a **callback**, the same `true` or `false` will be passed into the callback function.

```lua
local result = exports.vise_grid_memory_game:start()

if result then
    print('game completed')
else
    print('game failed')
end

-- You can also optionally use a callback to determine if game was completed or not
exports.vise_grid_memory_game:start(settings, function(result)
    if result then
        print('game completed')
    else
        print('game failed')
    end
end)
```

## 🔧 Settings

When starting the game, you can pass a **settings table** to customize how the game works.

Here are the available setting options:

* `gridSize` – How large grid game should have *(default: 3)*
* `tileDisplayTime` – How long (in milliseconds) each tile is previewed *(default: 250)*
* `levelTimeout` – How long (in milliseconds) the player has to complete each level *(default: 8000)*
* `targetScore` – How many levels the player has to complete to complete the game *(default: 6)*

**Example settings:**

```lua
local settings = {
    gridSize = 3,
    tileDisplayTime = 250,
    levelTimeout = 8000,
    targetScore = 6,
}
```

## 📦 Usage Examples

**Regular usage:**

```lua
local settings = {
    gridSize = 3,
    tileDisplayTime = 250,
    levelTimeout = 8000,
    targetScore = 6,
}

local result = exports.vise_letter_sequence_game:start(settings)

if result then
    print('game completed')
else
    print('game failed')
end
```

**Callback usage:**

```lua
local settings = {
    gridSize = 3,
    tileDisplayTime = 250,
    levelTimeout = 8000,
    targetScore = 6,
}

exports.vise_letter_sequence_game:start(settings, function(result)
    if result then
        print('game completed')
    else
        print('game failed')
    end
end)
```
