# Syntax help with expression tag

**URL:** <https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042>\
**Category:** Ignition\
**Created:** [June 14, 2023, 8:26pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042 "2023-06-14T20:26:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 14, 2023, 8:26pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/1 "2023-06-14T20:26:26Z")

</div>

Need help with expression tag returns tag value if hour is correct  
if{[.]hour}=15,{[.]Crank\_max,0}

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [June 14, 2023, 8:28pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/2 "2023-06-14T20:28:07Z")

</div>

See this doc,  
[https://docs.inductiveautomation.com/display/DOC80/if](https://docs.inductiveautomation.com/display/DOC80/if)

Probably something like,

```auto
if({[.]hour}=15,{[.]Crank_max},0)

```

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 14, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/3 "2023-06-14T20:42:29Z")

</div>

is there a way that I can just return the true value? I just want this to happen one time when the hour is15, I just want to store the crank\_max value in that tag. like a one shot

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 14, 2023, 8:44pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/4 "2023-06-14T20:44:22Z")

</div>

Not with an expression, which must _always_ return a value, by definition.

If you want to do something as a 'side effect' of a tag changing, you want a script. Potentially a tag event script on `hour`, where every time it changes, if the hour == 15, it will write the value of `Crank_max` to another tag.

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 14, 2023, 8:46pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/5 "2023-06-14T20:46:43Z")

</div>

yes, what does that look like?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 14, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/6 "2023-06-14T20:58:21Z")

</div>

Something like:

```python
if currentValue.value == 15
    crankMax = system.tag.readBlocking(["[.]Crank_max"])[0].value
    system.tag.writeBlocking(["[.]SomeMemoryTag"], [crankMax])

```

Assuming all your tags are colocated in the same folder.

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 14, 2023, 9:19pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/7 "2023-06-14T21:19:46Z")

</div>

could I do that for multiple values in the same script? currentValue.value == 5, ==1, == 9.  
Just duplicate the script using the same["[.]SomeMemoryTag"]. I want assign the value of Crank\_max when the hour = 5 or 1 or 9 to["[.]SomeMemoryTag"]

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 14, 2023, 9:23pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/8 "2023-06-14T21:23:42Z")

</div>

Yes, either use:  
`if currentValue.value == 15 or currentValue.value == 9 or currentValue.value == 1` (and so on)  
_or_  
put your conditions into a data structure like a list and check for membership with `in`:

```python
hoursToCheck = [1, 5, 9, 15]
if currentValue.value in hoursToCheck:
    crankMax = system.tag.readBlocking(["[.]Crank_max"])[0].value
    system.tag.writeBlocking(["[.]SomeMemoryTag"], [crankMax])

```

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 15, 2023, 12:26pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/9 "2023-06-15T12:26:26Z")

</div>

do I leave this line or remove it?  
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 15, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/10 "2023-06-15T12:29:50Z")

</div>

That line is not removable. All scripting underneath that line needs to be indented one tab.

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 15, 2023, 12:41pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/11 "2023-06-15T12:41:41Z")

</div>

still getting scripting error expecting colon -  
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
if currentValue.value == 5 or currentValue == 13 or currentValue.value == 21 or currentValue.value == 8  
crank\_max = system.tag.readBlocking( ["[.]Crank\_max"]) [0].value  
system.tag.writeBlocking( ["[.]P1\_Target"], [crank\_max])

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 15, 2023, 12:42pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/12 "2023-06-15T12:42:49Z")

</div>

Please use the "preformatted text" button in the comment editor to style your pasted code so we can read it.

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 15, 2023, 12:45pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/13 "2023-06-15T12:45:45Z")

</div>

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value == 5 or currentValue == 13 or currentValue.value == 21 or currentValue.value == 8
		crank_max = system.tag.readBlocking(["[.]Crank_max"])[0].value
		system.tag.writeBlocking(["[.]P1_Target"], [crank_max])

```

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 15, 2023, 12:49pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/14 "2023-06-15T12:49:08Z")

</div>

forgot to add the .value on second line but still getting same error

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 15, 2023, 12:51pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/15 "2023-06-15T12:51:52Z")

</div>

You are missing a colon on the end of your `if` statement. Common python mistake that the error message was trying to tell you.

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 15, 2023, 12:54pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/16 "2023-06-15T12:54:10Z")

</div>

Thanks Phil, don't do a lot of scripting. Is there examples on how to properly write these scripts

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 15, 2023, 12:57pm UTC](https://forum.inductiveautomation.com/t/syntax-help-with-expression-tag/75042/17 "2023-06-15T12:57:16Z")

</div>

Online python tutorials would be best. But be aware the CPython 2.7 is long-dead, while Jython 2.7 is current (for a number of reasons, mostly good). When looking at online docs for v2.7, you have to ignore the big, colorful warning banner about the old version.
