# Word Memory

## ⚙️Installation

1. Download `vise_word_memory_game` resource from Cfx.re Keymaster
2. Extract `vise_word_memory_game` into your server's resources directory
3. Add `ensure vise_word_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_word_memory_game:start()

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

**✅ Using the test command:**

Type command `/test_vise_word_memory_game` in-game.

{% tabs %}
{% tab title="Video preview" %}
{% embed url="<https://youtu.be/VuuLLhcNqk4?t=48>" %}
Game can be seen at 0:48-1:09
{% 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%2FW8o29IQ7A2CWfoC4lc1Q%2Fvise_word_memory_main.png?alt=media&#x26;token=8e77e7d4-3770-44ff-a8c7-621773ae0323" 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%2Flms8Hf5h4zA4YjkVPPZk%2Fvise_word_memory_win.png?alt=media&#x26;token=235bbf07-9599-4492-9a1d-ca60e2c40103" 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%2F1nMZo9H9d63LZ1zI3vYg%2Fvise_word_memory_lose.png?alt=media&#x26;token=7b25cc3d-a5f5-411d-bbeb-f2f7f4d8897b" 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_word_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_word_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:

* `targetScore` – How many correct answers to win the game *(default: 15)*
* `wordTimeout` – How long (in seconds) the player has to decide for each word *(default: 5)*

**Example settings:**

```lua
local settings = {
  targetScore = 15,
  wordTimeout = 5,
}
```

## 📦 Usage Examples

**Regular usage:**

```lua
local settings = {
  targetScore = 15,
  wordTimeout = 5,
}

local result = exports.vise_word_memory_game:start(settings)

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

**Callback usage:**

```lua
local settings = {
  targetScore = 15,
  wordTimeout = 5,
}

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