# Component Scripting If statement based on tag value

**URL:** <https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889>\
**Category:** Ignition\
**Tags:** vision, scripting, ignition80\
**Created:** [October 21, 2020, 6:51pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889 "2020-10-21T18:51:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtrimbleS](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jtrimbleS](https://forum.inductiveautomation.com/u/jtrimbleS)\
**Post date:** [October 21, 2020, 6:51pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/1 "2020-10-21T18:51:52Z")

</div>

I am trying to write a component script that will either display a message box or write a value to a tag based on the value of another tag. Here is what I have as of now:

if ‘[edge]PLC\_3010\_SJD\_2/Test\_Tag.value’ \<\> 0:  
system.gui.messageBox(‘Pump Change Already in Progress… Please wait’)

else:

```
if system.gui.confirm("Are you sure you want to start system?","Confirm",1):
	tagpath ='[edge]PLC_3010_SJD_2/Controller:Global/F_3010_LSP_15' + event.source.parent.pump_number + '0_HMI_start'
	value = 1

	system.tag.write(tagpath, value)
else:	
	end

```

The second if statement writing the value to a tag works fine. The initial if statement doesn’t seem to care what the value of the “Test\_Tag” is. I am assuming I have the syntax wrong for "referencing a tag value, but I have not been able to find what the correct syntax is, or if its possible.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [October 21, 2020, 6:55pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/2 "2020-10-21T18:55:58Z")

</div>

> [@jtrimbleS](#):
>
> ‘[edge]PLC\_3010\_SJD\_2/Test\_Tag.value’

Should be  
`if system.tag.read(‘[edge]PLC_3010_SJD_2/Test_Tag').value<>0:`

---

<div class="post-metadata">

**Author:** ![jtrimbleS](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jtrimbleS](https://forum.inductiveautomation.com/u/jtrimbleS)\
**Post date:** [October 21, 2020, 7:11pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/3 "2020-10-21T19:11:28Z")

</div>

Thank you for the reply. The script does run with no errors, but the if statement runs regardless of the value of Test\_Tag. When the value is 0 I still get the Message Box.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 21, 2020, 7:20pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/4 "2020-10-21T19:20:25Z")

</div>

What type is Test\_Tag?

---

<div class="post-metadata">

**Author:** ![jtrimbleS](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jtrimbleS](https://forum.inductiveautomation.com/u/jtrimbleS)\
**Post date:** [October 21, 2020, 7:33pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/5 "2020-10-21T19:33:13Z")

</div>

Test\_Tag is an integer. It is a memory tag that I am using for testing purposes only. The actual tag used will be an OPC Tag also an integer.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 21, 2020, 7:35pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/6 "2020-10-21T19:35:02Z")

</div>

can you post the script after the changes recommended by @MMaynard, because assuming that Test\_Tag value is actually 0 the script should work.

---

<div class="post-metadata">

**Author:** ![jtrimbleS](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jtrimbleS](https://forum.inductiveautomation.com/u/jtrimbleS)\
**Post date:** [October 21, 2020, 7:48pm UTC](https://forum.inductiveautomation.com/t/component-scripting-if-statement-based-on-tag-value/39889/7 "2020-10-21T19:48:32Z")

</div>

Apologies. I just double checked and I had kept the .value portion inside the parentheses when I updated. placing that portion outside the parentheses works.
