# How to access custom variables and methods of authoritative match handler in other modules?

**URL:** <https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512>\
**Category:** Runtime Framework\
**Created:** [April 9, 2022, 1:30pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512 "2022-04-09T13:30:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amuuu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/amuuu/32/1048_2.png) [@amuuu](https://forum.heroiclabs.com/u/amuuu)\
**Post date:** [April 9, 2022, 1:30pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/1 "2022-04-09T13:30:04Z")

</div>

Hello,

I’m making a match handler on Lua runtime. The match handler itself has some variables and methods besides the needed functions for a match handler such as the `match_loop` or `match_join`. I have defined my own variables and methods that should exist for each match (so, not global) like this:

```lua
local M = { a_variable = -1 }

function M.a_method()
    nk.logger_info("sth")
end

function M.match_leave(...)
    -- ...
end 
...

```

I want to make an RPC so that the client can access the `a_variable` of their own match. I saw the source code and found that there is a function `nk.match_get(match_id)`. But it doesn’t seem to give me access to the `a_variable` or the `a_method` that I created for my runtime match handler.

Can you help me with this?

Nakama 3.11.0; Docker; CockroachDB;

---

<div class="post-metadata">

**Author:** ![formatCvt](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/formatcvt/32/1127_2.png) [@formatCvt](https://forum.heroiclabs.com/u/formatCvt)\
**Post date:** [April 9, 2022, 2:44pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/2 "2022-04-09T14:44:33Z")

</div>

> [@amuuu](#):
>
> I have defined my own variables and methods that should exist for each match

You should store these variables in storage i think - [https://heroiclabs.com/docs/nakama/server-framework/function-reference/lua/#Storage](https://heroiclabs.com/docs/nakama/server-framework/function-reference/lua/#Storage)

---

<div class="post-metadata">

**Author:** ![amuuu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/amuuu/32/1048_2.png) [@amuuu](https://forum.heroiclabs.com/u/amuuu)\
**Post date:** [April 11, 2022, 6:46am UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/4 "2022-04-11T06:46:03Z")

</div>

@formatCvt

Thank you!  
Yes that will work for sure. I was just wondering if there’s a way to access the match handler variables directly.

The function header for the MatchGet is `MatchGet(ctx context.Context, id string) (*api.Match, error)`

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [April 11, 2022, 1:26pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/5 "2022-04-11T13:26:04Z")

</div>

Hey @amuuu, `get_match()` won’t return you variables or methods you declared in code. It does return the match handler name, so you could store it as a key using the storage engine together with your relevant variables/data.

---

<div class="post-metadata">

**Author:** ![amuuu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/amuuu/32/1048_2.png) [@amuuu](https://forum.heroiclabs.com/u/amuuu)\
**Post date:** [April 12, 2022, 6:15am UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/6 "2022-04-12T06:15:57Z")

</div>

@ftkg  
Thank you I have to use the storage engine then.

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [April 13, 2022, 1:59pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/7 "2022-04-13T13:59:26Z")

</div>

@amuuu Also worth noting there may be other ways to achieve what you need. What exactly will these variables/functions be doing, and how will they be accessed?

If it’s clients that need to call them then you should do this via match data sends with specific opcodes you designate - when the match loop receives those opcodes it would trigger the correct function on behalf of the user, and return the results via a broadcast if needed.

---

<div class="post-metadata">

**Author:** ![amuuu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/amuuu/32/1048_2.png) [@amuuu](https://forum.heroiclabs.com/u/amuuu)\
**Post date:** [April 13, 2022, 9:33pm UTC](https://forum.heroiclabs.com/t/how-to-access-custom-variables-and-methods-of-authoritative-match-handler-in-other-modules/2512/8 "2022-04-13T21:33:09Z")

</div>

@zyro thanks for the response!  
The main thing that I do with those variables is managing some gameplay roles and ID assignments.  
I wanted the clients to use the RPC to get the latest version of that data structure every few seconds.

If the server broadcasts its updated data structure whenever someone leaves or joins, I think the opcodes that you mentioned is quite useful. The only thing that I don’t know, is whether it’s possible to broadcast match state messages to presences from inside of `match_leave` or `match_join` methods directly, like using some nakama runtime method.
