# Phython coding help

**URL:** <https://forum.inductiveautomation.com/t/phython-coding-help/99011>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 22, 2024, 7:20pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011 "2024-11-22T19:20:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chad\_spangler](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chad\_spangler](https://forum.inductiveautomation.com/u/chad_spangler)\
**Post date:** [November 22, 2024, 7:20pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/1 "2024-11-22T19:20:46Z")

</div>

I have this Code

 ![Screenshot 2024-11-22 142032](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/aeb36c317f446f086019b45f1066cb82cdcfefd6.png)  
:

Why is it when barge source is not true it saves a 0 into target percent? I am newer to Phython coding sorry if this is a silly question but ChatGPT couldn't solve it for me so here i am.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 22, 2024, 7:38pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/3 "2024-11-22T19:38:22Z")

</div>

Have you confirmed the type of value you are getting from barge source? Is it actually a boolean or is it a string? Strings of non zero length are treated as true when coerced to a boolean.

---

<div class="post-metadata">

**Author:** ![chad\_spangler](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chad\_spangler](https://forum.inductiveautomation.com/u/chad_spangler)\
**Post date:** [November 22, 2024, 7:38pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/4 "2024-11-22T19:38:28Z")

</div>

```python
def runAction(self, event):
	barge_source_silo_1 = system.tag.read("[West Point]BargeSourceSilo1Mem").value
	

    # Target percent memory tags
	target_percent_mem_1 = system.tag.read("[West Point]Silo1TargetPercentMem").value

    # Non-memory target percent tags (the ones that are written to)
	target_percent_1 = "[West Point]Silo1TargetPercent"

    # Check each barge source and write the corresponding target percent
	if barge_source_silo_1 == True:
		system.tag.write(target_percent_1, target_percent_mem_1)

```

---

<div class="post-metadata">

**Author:** ![chad\_spangler](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chad\_spangler](https://forum.inductiveautomation.com/u/chad_spangler)\
**Post date:** [November 22, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/5 "2024-11-22T19:40:09Z")

</div>

Yes it is a memory tag that I made boolean. Just double checked aswell.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 22, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/6 "2024-11-22T19:44:31Z")

</div>

I would recommend using `system.util.getLogger` and logging the value or `system.perspective.print()` to print the value at button press. If it really is a boolean it is certainly not seeing `if False == True` and proceeding.

Also `system.tag.read` is deprecated, use `system.tag.readBlocking` instead.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 22, 2024, 7:50pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/7 "2024-11-22T19:50:43Z")

</div>

Is this action script on a button? Are you trying to prevent writing a value to `target percent` unless some other requirement is met that makes `barge source` true? Could you explain the overall use case for us? There may be an approach that requires less code.

Also, if you decide to use system.tag.readBlocking, the `system.tag.read*()` functions return a list of [Qualified Value Objects](https://www.docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/scripting-object-reference#qualifiedvalue).

A qualified value has value, quality, and timestamp attributes. To get the value you must access the value attribute of the Qualified Value element at the index corresponding to the tag path.

```python
actualValue = system.tag.readBlocking(['TagPath\Tag_1'])[0].value

```

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [November 22, 2024, 7:56pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/8 "2024-11-22T19:56:53Z")

</div>

you can also use `type(barge_source_silo_1)` to confirm.

---

<div class="post-metadata">

**Author:** ![chad\_spangler](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chad\_spangler](https://forum.inductiveautomation.com/u/chad_spangler)\
**Post date:** [November 22, 2024, 8:10pm UTC](https://forum.inductiveautomation.com/t/phython-coding-help/99011/9 "2024-11-22T20:10:43Z")

</div>

Well embarrassingly enough I figured out the issue. The guy on the PLC side had something that 0ed them and the connection between the PLC and ignition is almost instant. So knowing my python ignorance I assumed I was doing something wrong. But all fixed thanks for the help guys
