# Increment/decrement property using core nodes

**URL:** https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004
**Category:** General
**Created:** [21 January 2022 10:01 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004 "2022-01-21T10:01:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 January 2022 10:01 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/1 "2022-01-21T10:01:41Z")

</div>

My cheerlights flow got itself trapped in a loop so I want to add a counter and get it to give up after 10 attempts

So I added a change node at start of flow to set flow.attempts to 10 and then added a switch later on in the loop to detect if attempts \< 0

Then I went to add something to decrement flow.attempts and realised that I couldn't come up with anything to do that (without code)

I'm wondering if maybe the change node could have an increment option added to let us do this?

Or is there an easy method I've missed?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 January 2022 10:10 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/2 "2022-01-21T10:10:49Z")

</div>

> [@cymplecy](#):
>
> Or is there an easy method I've missed?

Well, not as simple as chosing an `increment` drop down but, not sooo difficult  
 ![chrome_kZKrTYVwqn](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bd344b987cb3b6f70fc2bd1dd131167b85a4aec.gif)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b92190a0a7cce3374f19e5dc5ee59b421ba46fcf.png)

Simon, I sometimes think your aversion to function nodes is `counter` productive 😉 (see what I did there 😆 )

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 January 2022 10:16 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/3 "2022-01-21T10:16:09Z")

</div>

I am the ultimate block-based programmer evangelist - someone has to fight the good fight 🙂

Node-RED should (IMO) always (as it does in LOTS of cases) let us do simple operations without coding

And of course, even when I code, I 99% use Bart's Blockly node 🙂

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [21 January 2022 11:19 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/4 "2022-01-21T11:19:47Z")

</div>

Actually I can envisage a simple node that does things like this... but of course the instant reaction is scope creep... I would want simple add, subtract, multiply, divide etc of the "payload" by a constant, (eg see Steve's buffer parser) or flow/global property... oh and then combinations like multiply and add etc (degC to degF etc). - oh then maybe AND, OR, XOR - etc etc... Not saying it can't be done (probably should be) - - but needs some design work first - and then indeed should it be part of the change node ? (see other recent discussions on change node) - or a new numeric only calculator node ?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [21 January 2022 11:28 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/5 "2022-01-21T11:28:00Z")

</div>

This is something I've been thinking about - having a core set of nodes for common operations on standard JavaScript types.

There is already the [node-red-contrib-string](https://flows.nodered.org/node/node-red-contrib-string) as a node that provides common string functions - not saying that's quite the model I had in mind, but it is along those lines.

A `Maths` node could provide operations for numeric types.

An `Array` node could do simple push/pop/splice etc type operations.

I think it would be worth putting together a concept for it.

Nick

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 January 2022 11:32 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/6 "2022-01-21T11:32:53Z")

</div>

Super duper 🙂

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [21 January 2022 12:03 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/7 "2022-01-21T12:03:03Z")

</div>

And maybe a conversions node? I could see that would be REALLY useful.

These nodes would also help take Node-RED into improving some areas that it is weak on compared to some other visual tools as well which would be nice. One day, it would be wonderful to be able to use Node-RED to do ETL tasks that people currently switch to Python for. 😀

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [21 January 2022 12:09 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/8 "2022-01-21T12:09:48Z")

</div>

I was wondering if the join node could have an add/minus/multiply/divide setting for numbers with a starting number?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 January 2022 12:13 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/9 "2022-01-21T12:13:06Z")

</div>

I just wanted to subtract 1 from a number .......

🙂

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [21 January 2022 12:13 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/10 "2022-01-21T12:13:59Z")

</div>

Surely you can do that in the blockly node 🤣

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 January 2022 12:21 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/11 "2022-01-21T12:21:36Z")

</div>

If someone does a node-red-contrib-just-subtract-one node, can they also assemble an end to end illustrated tutorial to get from the idea **n -=1** to a published node?

It's an intimidating stage of the learning curve.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 January 2022 12:21 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/12 "2022-01-21T12:21:51Z")

</div>

> [@dceejay](#):
>
> but of course the instant reaction is scope creep

Dave, can i borrow your crystal ball please?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a808a115e73724d3412262dab58450e679d0aa06.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [21 January 2022 14:07 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/13 "2022-01-21T14:07:22Z")

</div>

> [@TotallyInformation](#):
>
> And maybe a conversions node?

eg see -

> **[node-red-contrib-unit-converter](https://flows.nodered.org/node/node-red-contrib-unit-converter)**
>
> A Node Red node for unit conversions

> [@cymplecy](#):
>
> I just wanted to subtract 1

... that's how it always starts... 🙂

> [@Steve-Mcl](#):
>
> can i borrow your crystal ball please?

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a366cbe2944e858aa167cf6f90d02c2c721e663.png)

> [@knolleary](#):
>
> A `Maths` node could

... or should that be a "Math" node ...

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 January 2022 14:28 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/14 "2022-01-21T14:28:50Z")

</div>

> [@dceejay](#):
>
> > [@TotallyInformation](#):
> >
> > And maybe a conversions node?
> 
> eg see -
> 
> [node-red-contrib-unit-converter (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-unit-converter)

You know, I read and re-read Julians comment as a **conversations** node. I pondered and pondered and ...

I was scared to ask about what sorcery I was missing out on.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [21 January 2022 14:32 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/15 "2022-01-21T14:32:05Z")

</div>

It's Friday... I was too blinkered to think that far out of the box... if he had said that I would have missed it

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [21 January 2022 14:33 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/16 "2022-01-21T14:33:40Z")

</div>

> [@dceejay](#):
>
> or should that be a "Math" node

That is a can of worms you just opened. I'm with knolleary on this.

> The only difference is that math is preferred in the U.S. and Canada, and maths is preferred in the U.K., Australia, and most other English-speaking areas of the world.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [21 January 2022 14:34 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/17 "2022-01-21T14:34:36Z")

</div>

me too... I was just have a Friday afternoon moment...

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [21 January 2022 14:37 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/18 "2022-01-21T14:37:28Z")

</div>

> [@E1cid](#):
>
> st opened. I'm with knolleary on this.

I very nearly wrote `Math(s)` in my original reply... but my en\_GB nature shone through.

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [21 January 2022 15:37 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/19 "2022-01-21T15:37:04Z")

</div>

There was a recent conversation on slack about adding a `local` context to the `change` node, perfect for things like keeping a counter that can be modified by any expression syntax... perhaps it's time to rethink that as it's a general purpose solution?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02d62bd64658cede2de39c961ee612759e789a94.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [21 January 2022 15:45 UTC](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004/20 "2022-01-21T15:45:44Z")

</div>

> [@dceejay](#):
>
> It's Friday... I was too blinkered to think that far out of the box... if he had said that I would have missed it

And I think we have now demonstrated that _we_ are the wolves in the out-of-control trolley!

[Next page](https://discourse.nodered.org/t/increment-decrement-property-using-core-nodes/57004.md?page=2)
