# What is Opcode and how it works?

**URL:** <https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729>\
**Category:** Game Design\
**Tags:** sdk-unity\
**Created:** [June 9, 2022, 7:05am UTC](https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729 "2022-06-09T07:05:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sana2024](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sana2024/32/1170_2.png) [@sana2024](https://forum.heroiclabs.com/u/sana2024)\
**Post date:** [June 9, 2022, 7:05am UTC](https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729/1 "2022-06-09T07:05:57Z")

</div>

hi everyone, I’m new to Nakama and I want to understand Opcodes better, what are they and how can I set them, what type of data can be included in it and what is it’s relationship with sending and receiving messages??

I need some examples in code with c#

thanks in advance.

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [June 9, 2022, 9:01am UTC](https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729/2 "2022-06-09T09:01:46Z")

</div>

Please see the documentation on [Op Codes](https://heroiclabs.com/docs/nakama/concepts/multiplayer/relayed/#op-codes) and [examples of how to use them](https://heroiclabs.com/docs/nakama/tutorials/unity/fishgame/#sending-player-position).

---

<div class="post-metadata">

**Author:** ![sana2024](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sana2024/32/1170_2.png) [@sana2024](https://forum.heroiclabs.com/u/sana2024)\
**Post date:** [June 9, 2022, 9:23am UTC](https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729/3 "2022-06-09T09:23:53Z")

</div>

what I’m understanding is that you have to set an Opcode for every action you want to transfer through the network, and you will also create a dictionary for that action in a set of key and values to give data to that action and then convert it to Json inside the MatchDataJson  
and then you combine these two information inside the sendMatchState  
we will give it the match id, the opcode and the state we created in the Json Data class  
we can specify that in the player every time we want to send an action,

and now what is left for me to understand is the receiving part  
what is " var state = matchState.State.Length \> 0 ? System.Text.Encoding.UTF8.GetString(matchState.State).FromJson\<Dictionary\<string, string\>\>() : null; "  
inside the onReceive function???

and what is the match state ???  
does the “FromJson” part gives back the data we created inside the MatchDataJson class??  
what does that part do??

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [June 9, 2022, 1:38pm UTC](https://forum.heroiclabs.com/t/what-is-opcode-and-how-it-works/2729/4 "2022-06-09T13:38:11Z")

</div>

The line of code you shared is checking to see if any state data is being received. If so, it turns it into a UTF8 encoded string and then parses it as a `Dictionary<string, string>` object.

For further information please see the [Receiving match state](https://heroiclabs.com/docs/nakama/client-libraries/unity/index.html#receiving-match-sate) documentation in our [Unity Client Guide](https://heroiclabs.com/docs/nakama/client-libraries/unity/).
