# ValueChanged string format breaks

**URL:** <https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903>\
**Category:** Ignition\
**Created:** [May 6, 2025, 7:04am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903 "2025-05-06T07:04:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick\_de\_Man](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rick_de_man/32/75670_2.png) [@Rick\_de\_Man](https://forum.inductiveautomation.com/u/Rick_de_Man)\
**Post date:** [May 6, 2025, 7:04am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/1 "2025-05-06T07:04:34Z")

</div>

I Have a ValueChanged script on a tag and when string format function is within the code it completely breaks and fails to execute, not even the Gateway logs show any errors.

The following line wil make the ValueChange script unusable.

```python
test = "{0}".format( "abcd" )

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 6, 2025, 7:16am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/2 "2025-05-06T07:16:25Z")

</div>

Do you get an error in the logs ?  
Can we see the whole script ?

---

<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:** [May 6, 2025, 10:28am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/3 "2025-05-06T10:28:19Z")

</div>

You basically cannot use modern python's `.format()` in tag events, as the curly braces are mis-interpreted. There is no work-around. Use classic `%` formatting instead.

---

<div class="post-metadata">

**Author:** ![Rick\_de\_Man](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rick_de_man/32/75670_2.png) [@Rick\_de\_Man](https://forum.inductiveautomation.com/u/Rick_de_Man)\
**Post date:** [May 6, 2025, 10:58am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/4 "2025-05-06T10:58:35Z")

</div>

Phil,

Could you show me a working example since I am not yet familiar with that method.

---

<div class="post-metadata">

**Author:** ![Rick\_de\_Man](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rick_de_man/32/75670_2.png) [@Rick\_de\_Man](https://forum.inductiveautomation.com/u/Rick_de_Man)\
**Post date:** [May 6, 2025, 11:01am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/5 "2025-05-06T11:01:03Z")

</div>

> [@pascal.fragnoud](#):
>
> Do you get an error in the logs ?  
> Can we see the whole script ?

That's the full code what wil break the working. The entire code is irrelevant to the problem.

There is an error but not shown/visible to the client and the gateway does not log the issue.  
I had to find out why the SaveChange did not execute as expected.

---

<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:** [May 6, 2025, 11:02am UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/6 "2025-05-06T11:02:56Z")

</div>

> [@Rick\_de\_Man](#):
>
> show me

`"%s" % "abcd"`

I should also mention that you can avoid the problem by having your event be a one-liner that delegates to a function in the gateway scripting project's library. (You should do this for all events in Ignition anyways.)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 6, 2025, 2:47pm UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/7 "2025-05-06T14:47:09Z")

</div>

> [@pturmel](#):
>
> You basically cannot use modern python's `.format()` in tag events,

Noo, it's just when using identifiers within the braces that it dies. Get rid of that 0 in the brackets and you're good to go

Ie

`test = "{}".format( "abcd" )`

---

<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:** [May 6, 2025, 2:50pm UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/8 "2025-05-06T14:50:32Z")

</div>

> [@nminchin](#):
>
> and you're good to go

Awfully fragile, and sets developers up for failure. Using the `%` operator is effectively bullet-proof, which is why I use it everywhere.

Not all that is new is not dumb.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 6, 2025, 2:55pm UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/9 "2025-05-06T14:55:57Z")

</div>

format is a perfectly good method though, I use it everywhere and have never run into an issue, albeit I don't normally use identifiers in them. The updates to it in python 3 make it much nicer to use with f strings though

The only issue with it within change events is IA's code to parse it which fails for named parameters

---

<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:** [May 6, 2025, 3:07pm UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/10 "2025-05-06T15:07:32Z")

</div>

> [@nminchin](#):
>
> which fails

Hmmm? My point?

---

<div class="post-metadata">

**Author:** ![Rick\_de\_Man](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rick_de_man/32/75670_2.png) [@Rick\_de\_Man](https://forum.inductiveautomation.com/u/Rick_de_Man)\
**Post date:** [May 6, 2025, 3:45pm UTC](https://forum.inductiveautomation.com/t/valuechanged-string-format-breaks/105903/11 "2025-05-06T15:45:06Z")

</div>

> [@pturmel](#):
>
> I should also mention that you can avoid the problem by having your event be a one-liner that delegates to a function in the gateway scripting project's library. (You should do this for all events in Ignition anyways.)

I am currently refactoring everything to create a complete UNS design and all functions are now placed in scripting (also great for testing).

In a very specific case I came across this piece and will migrate to a script, I did wanted to know why it broke.

Thank!
