# Function tried to send a message of type number

**URL:** <https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960>\
**Category:** General\
**Created:** [21 March 2021 13:36 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960 "2021-03-21T13:36:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PiMo131](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pimo131/32/34978_2.png) [@PiMo131](https://discourse.nodered.org/u/PiMo131)\
**Post date:** [21 March 2021 13:36 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/1 "2021-03-21T13:36:01Z")

</div>

Hi,

i am trying to do some basic calculations but keep getting the error 'function tried to send a message of type number'.

I read most forum discussion and added = {}; in the beginning of the flow for all variables.. but this did not fix the issue.

```auto
var meting = {};
var gem = {};
var stddev = {};
var gemstd = {};
var metstd = {};

meting = msg.payload;
gem = msg.average;
stddev = flow.get("stddev");
gemstd = gem + stddev;
metstd = meting + stddev;

meting.payload= msg.payload;
meting.topic= "meting";
gem.payload= msg.average;
gem.topic= "gemiddelde";
gemstd.topic = "gem +stddev";
gemstd.payload = gemstd;
metstd.topic = "meting +stddev";
metstd.payload = metstd;

return [meting, gem, metstd, gemstd]

```

the issue is probably obvision, but I can't find it....

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 March 2021 14:07 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/2 "2021-03-21T14:07:00Z")

</div>

You are correctly creating empty messages at the start, but then you say, for example,

```auto
meting = msg.payload;

```

which destroys the empty message you had already created. Then you say

```auto
meting.payload= msg.payload;

```

which I am suprised does not generate an error. Possibly you intended to create a separate set of temporary variables instead of overwriting `meting` and the others.

---

<div class="post-metadata">

**Author:** ![PiMo131](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pimo131/32/34978_2.png) [@PiMo131](https://discourse.nodered.org/u/PiMo131)\
**Post date:** [21 March 2021 14:07 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/3 "2021-03-21T14:07:00Z")

</div>

after some reading I figured I should take out the 'var meting = {};' and 'var gem = {};'  
since it deletes the payload before i use them... But also making that change did not resolve the issue:

```auto
var stddev = {};
var gemstd = {};
var metstd = {};

var meting = msg.payload;
var gem = msg.average;
stddev = flow.get("stddev");
gemstd = gem + stddev;
metstd = meting + stddev;

meting.payload= meting;
meting.topic= "meting";
gem.payload= gem;
gem.topic= "gemiddelde";
gemstd.topic = "gem +stddev";
gemstd.payload = gemstd;
metstd.topic = "meting +stddev";
metstd.payload = metstd;

return [gemstd, metstd, meting, gem]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 March 2021 14:07 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/4 "2021-03-21T14:07:59Z")

</div>

> [@PiMo131](#):
>
> after some reading I figured I should take out the 'var meting = {};' and 'var gem = {};'

I think those are correct, it is the overwriting of them that is the problem

---

<div class="post-metadata">

**Author:** ![PiMo131](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pimo131/32/34978_2.png) [@PiMo131](https://discourse.nodered.org/u/PiMo131)\
**Post date:** [21 March 2021 14:13 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/5 "2021-03-21T14:13:19Z")

</div>

Thanks Colin, i Understand. fixed it!

```auto
var G = {};
var GS = {};
var M = {};
var MS = {};

var meting = msg.payload;
var gem = msg.average;
var stddev = flow.get("stddev");
var gemstd = gem + stddev;
var metstd = meting + stddev;

M.payload= meting;
M.topic= "meting";
G.payload= gem;
G.topic= "gemiddelde";
GS.topic = "gem +stddev";
GS.payload = gemstd;
MS.topic = "meting +stddev";
MS.payload = metstd;

return [G, GS, M, MS]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 April 2021 14:13 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-number/42960/6 "2021-04-04T14:13:55Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
