# How to call an RPC custom function inside another function (each in a different file)

**URL:** <https://forum.heroiclabs.com/t/how-to-call-an-rpc-custom-function-inside-another-function-each-in-a-different-file/4605>\
**Category:** Runtime Framework\
**Tags:** server-framework, lua\
**Created:** [November 14, 2023, 9:17pm UTC](https://forum.heroiclabs.com/t/how-to-call-an-rpc-custom-function-inside-another-function-each-in-a-different-file/4605 "2023-11-14T21:17:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Firemanarg](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@Firemanarg](https://forum.heroiclabs.com/u/Firemanarg)\
**Post date:** [November 14, 2023, 9:17pm UTC](https://forum.heroiclabs.com/t/how-to-call-an-rpc-custom-function-inside-another-function-each-in-a-different-file/4605/1 "2023-11-14T21:17:34Z")

</div>

Hey guys! How can I call an registered rpc function from another server script?

Example:

1. RPC function declaration and register:

```lua
-- file1.lua

function get_value(_, _)
  return nk.json_encode({value = 42})
end

nk.register_rpc(get_value, "get_value")

```

1. Call function inside another file

```lua
-- file2.lua

function custom_rpc_func(context, payload)
  ...
  local value = nk.json_decode("-- HERE someway call the function 'get_value' and get it's response --")
  ...
end

```

---

<div class="post-metadata">

**Author:** ![flavio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/flavio/32/2161_2.png) [@flavio](https://forum.heroiclabs.com/u/flavio)\
**Post date:** [November 15, 2023, 10:43am UTC](https://forum.heroiclabs.com/t/how-to-call-an-rpc-custom-function-inside-another-function-each-in-a-different-file/4605/2 "2023-11-15T10:43:22Z")

</div>

Hello @Firemanarg,

What is the error you’re getting? How are you importing the function from file1 into the code in file2?

---

<div class="post-metadata">

**Author:** ![Firemanarg](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@Firemanarg](https://forum.heroiclabs.com/u/Firemanarg)\
**Post date:** [November 15, 2023, 12:29pm UTC](https://forum.heroiclabs.com/t/how-to-call-an-rpc-custom-function-inside-another-function-each-in-a-different-file/4605/3 "2023-11-15T12:29:09Z")

</div>

I’m not getting any error. The point is that I don’t know how to call the function in another file 😂

I haven’t found any example of this in documentation
