# Using a variable before definition in user-defined function

**URL:** <https://brian.discourse.group/t/using-a-variable-before-definition-in-user-defined-function/788>\
**Category:** Support\
**Created:** [27 September 2022 21:41 UTC](https://brian.discourse.group/t/using-a-variable-before-definition-in-user-defined-function/788 "2022-09-27T21:41:09Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [28 September 2022 13:11 UTC](https://brian.discourse.group/t/using-a-variable-before-definition-in-user-defined-function/788/4 "2022-09-28T13:11:26Z")

</div>

I see. In this case I think the simplest solution would be to 1) define one function for each group and 2) define all of them in the end, before the run function. If it is too much of a mess to not define the functions in the beginning, you could also manually define variable names instead of using `device.get_array_name`: the name of the spike monitor’s `count` variable is `brian::_array_spikemonitor_count`, with `spikemonitor` the name of the `SpikeMonitor` object. If you manually define these names with `SpikeMonitor(..., name='myname')` for each monitor, you can directly put this name into the code.

Note that if all you need from the spike monitor is the spike count (we probably discussed this before, apologies 🙂 ), then it would probably be easier to just have this information directly represented in the neuron equations, with something like `spike_count : integer` in the equations, and a `spike_count += 1` as part of the `reset`.

---

_[View the full topic](https://brian.discourse.group/t/using-a-variable-before-definition-in-user-defined-function/788)._
