Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Increment variable by 1

2,224 views
Skip to first unread message

bigdata...@gmail.com

unread,
Mar 20, 2017, 8:07:09 AM3/20/17
to Node-RED
Hi All,

How to increment the variable by 1 in nodered. It has to increment the value when the new document is added in Cloudant NoSQL.

Can any one please help me out in writing the function.

Regards,
Divya.

Nick O'Leary

unread,
Mar 20, 2017, 8:13:36 AM3/20/17
to Node-RED Mailing List
Hi,

In JavaScript, you increment a value by:

var i=0;
i = i+1;

which answers the question you've asked, but probably doesn't help you achieve what you want.

What does the message look like?  What value do you want to increment?

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/06d605e9-8ac7-4b7b-9320-ed59f84c43ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bigdata...@gmail.com

unread,
Mar 20, 2017, 8:39:26 AM3/20/17
to Node-RED
Thanks for reply.

How to print the value by incrementing on the debug console.

Regards,
Divya


On Monday, March 20, 2017 at 5:43:36 PM UTC+5:30, Nick O'Leary wrote:
Hi,

In JavaScript, you increment a value by:

var i=0;
i = i+1;

which answers the question you've asked, but probably doesn't help you achieve what you want.

What does the message look like?  What value do you want to increment?

Nick
On 20 March 2017 at 12:07, <bigdata...@gmail.com> wrote:
Hi All,

How to increment the variable by 1 in nodered. It has to increment the value when the new document is added in Cloudant NoSQL.

Can any one please help me out in writing the function.

Regards,
Divya.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Nick O'Leary

unread,
Mar 20, 2017, 8:52:41 AM3/20/17
to Node-RED Mailing List
>How to print the value by incrementing on the debug console.

Please answer my questions: What does the message look like?  What value do you want to increment?

Nick




To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

bigdata...@gmail.com

unread,
Mar 20, 2017, 9:08:16 AM3/20/17
to Node-RED
ok. We are getting the real time data. I want to save the data by assigning the starting with value 1. When the next data entered it should save with value 2 and so on.

Nick O'Leary

unread,
Mar 20, 2017, 9:18:59 AM3/20/17
to Node-RED Mailing List
> ok. We are getting the real time data. I want to save the data by assigning the starting with value 1. When the next data entered it should save with value 2 and so on.

So you want to add a property to your message that represents a count of how many messages have been received so far?


Nick





To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

bigdata...@gmail.com

unread,
Mar 21, 2017, 12:31:11 AM3/21/17
to Node-RED
Yes Nick Exactly...

ma...@jasspro.it

unread,
May 23, 2018, 2:15:41 AM5/23/18
to Node-RED
Hello

I'm trying to increment a variable by 1 every time that read a string.
My code is :

var counter;
if (msg.topic === "IN1ON") {
    counter = counter +1;
}

    if (counter == 10) {
                       counter=0;
                       return "value10";
                        }

return null;

But I didn't rean anything

Do you know why ?
Thanks

Mark Setrem

unread,
May 23, 2018, 2:24:53 AM5/23/18
to Node-RED
So there are several things that make your flow not work
1) In Node-RED the nodes have no memory of previous messages. So every time your function node gets a message counter is 0

2) You need to return an object not a variable

You can find out how to store a variable so that part 1 works here: https://nodered.org/docs/writing-functions#storing-data

The docs have some examples of writing flows and there’s also several online Node-RED tutorials that will show you how to structure a function node in Node-RED
Reply all
Reply to author
Forward
0 new messages