# Unable to compile code, on change script

**URL:** <https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 22, 2023, 11:51pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485 "2023-12-22T23:51:12Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 22, 2023, 11:51pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/1 "2023-12-22T23:51:12Z")

</div>

For some reason, Ignition does not like this code:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue and currentValue.value:
		if self.params.material_id > 0:
			self.custom.mat1 = self.params.material_id
		else:
			message = 'chg_lid_action'
			system.perspective.sendMessage(message)

```

No red indicators visible in the editor.  
This code has the same problem:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue and currentValue.value:
		message = 'chg_lid_action'
		system.perspective.sendMessage(message)

```

Both are executed against `view.params.properties`, e.g. `pos_1` and `action`, respectively.

Both have incoming values from a Popup, via a message handler. Almost every time I save the project, one or the other produces the error that `the code could not be compiled: null pointer exception`.

I know the second change script runs, because I can see the results in the browser.

Thoughts on what to look at?

If, the null pointer is pointing to the `currentValue`, why would it consider that object in this case? Do I need to include `previousValue` as well?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 23, 2023, 12:10am UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/2 "2023-12-23T00:10:29Z")

</div>

> [@mdemaris](#):
>
> Both are executed against `view.params.properties` ...

View parameters don't change. They're read once when the view is loaded and that's it!

That might be enough to get you started on finding a fix or a correct way to achieve your goal.

A few other things strike me as odd:

- Why check `currentValue and currentValue.value`? Surely checking the second proves the first is true as well?
- `if self.params.material_id > 0:`. Do you need the `> 0`?
- `system.perspective.sendMessage` requires a payload. Use `{}` if there is nothing to send. Ignition might be tolerating it for now but it could break in a later version.  
**system.perspective.sendMessage(messageType, payload, [scope], [sessionId], [pageId])**  
[system.perspective.sendMessage - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.perspective.sendMessage)

---

<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:** [December 23, 2023, 4:46am UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/3 "2023-12-23T04:46:19Z")

</div>

> [@Transistor](#):
>
> Why check `currentValue and currentValue.value`? Surely checking the second proves the first is true as well?

The first checks the currentValue object isn't None, the second checks its value.

> [@Transistor](#):
>
> `if self.params.material_id > 0:`. Do you need the `> 0`?

I actually always write the condition I looking for explicitly. There have been too many times I've relied on Python's implicit comparison (or whatever it's called) and it's resulted in failed code runs under certain circumstances

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 23, 2023, 8:05am UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/4 "2023-12-23T08:05:10Z")

</div>

> [@nminchin](#):
>
> The first checks the currentValue object isn't None, the second checks its value.

But if the first was `None` wouldn't the second test fail as well thereby making the first test redundant?

---

<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:** [December 23, 2023, 11:01am UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/5 "2023-12-23T11:01:55Z")

</div>

If you remove the first test you will get a "None type has no property 'currentValue'". Python short circuits if conditions which is why it doesn't fail with the two conditions

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 23, 2023, 11:22am UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/6 "2023-12-23T11:22:06Z")

</div>

> [@nminchin](#):
>
> Python short circuits if conditions ...

Ah, OK. So if it fails the first test it doesn't bother executing the rest of the `if`? I didn't know that.

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [December 24, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/7 "2023-12-24T13:03:53Z")

</div>

I think sendMessage requires two arguments, the second one being a dictionary.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 24, 2023, 1:09pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/8 "2023-12-24T13:09:17Z")

</div>

Correct. That was my last point in post #2.

---

<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:** [December 24, 2023, 2:49pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/9 "2023-12-24T14:49:07Z")

</div>

> [@nminchin](#):
>
> The first checks the currentValue object isn't None, the second checks its value.

Technically this is correct, however, currentValue should never be `None`. previousValue will be none on initial change, but if you’re not using it no need to check.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 26, 2023, 6:33pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/10 "2023-12-26T18:33:01Z")

</div>

> [@Transistor](#):
>
> View parameters don't change. They're read once when the view is loaded and that's it!

So, passing values back to an already loaded view, via the parameters, is not good practice, even with embedded views?  
If so, that means I need to use more message handlers to do the work that needs to be done.

> [@Transistor](#):
>
> `system.perspective.sendMessage` requires a payload.

Yeah, I forget to include this sometimes 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 26, 2023, 7:14pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/11 "2023-12-26T19:14:12Z")

</div>

> [@mdemaris](#):
>
> So, passing values back to an already loaded view, via the parameters, is not good practice, even with embedded views?

Good question!  
I would think that the Embedded View component is designed to retrigger the view on parameter change. I've just tried it out in Designer and it does work.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 26, 2023, 7:29pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/12 "2023-12-26T19:29:14Z")

</div>

If a message handler changes the value of a parameter, on an embedded view, does that qualify as an action that would trigger the change script on the parameter?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 26, 2023, 7:55pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/13 "2023-12-26T19:55:09Z")

</div>

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue and currentValue.value:
		message = 'chg_lid_action'
		payload = {}
		system.perspective.sendMessage(message, payload)

```

I just got another error upon saving the project that the code could not be compiled, even after adding the `payload`.

---

<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:** [December 26, 2023, 7:59pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/14 "2023-12-26T19:59:46Z")

</div>

> [@mdemaris](#):
>
> code could not be compiled

You'll need to closely examine that error message and the line of code it indicates is the problem. See if there's a squiggly red mark in code editor in the right margin.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 26, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/15 "2023-12-26T21:11:45Z")

</div>

> [@mdemaris](#):
>
> If a message handler changes the value of a parameter, ...

You can't change a view's parameter from within the view. They're read-only.

If you change the view parameter on an Embedded View parameter by a message handler (on the Embedded View component - not in the view being embedded) then it should work.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 26, 2023, 10:43pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/16 "2023-12-26T22:43:21Z")

</div>

Edit: This is a different one that popped up right after I added and saved it, but same error.  
Edit #2:  
Restarted Designer, neither params (with the below change script and the one mentioned in the script) exist. All changes are saved regularly, and now both are gone. However, the embedded view still "sees" the params because I can select them from the list (`props.params`).

I think it's because I made them non-persistent. I was thinking persistence pertained to the value the param held, not the param itself.

Another edit:  
I created the params again, and the script magically appeared.

Details of error:

```auto
java.lang.NullPointerException
com.inductiveautomation.ignition.common.GenericTransferrableException

Ignition v8.1.33 (b2023101913)
Java: Azul Systems, Inc. 17.0.8

```

Script, with no squigglies:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/e/7ee92abf6b70e4d9a878d6fe61626af5e9b84be5.png)

---

<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:** [December 26, 2023, 10:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/17 "2023-12-26T22:56:16Z")

</div>

That's not a compile error. That's an execution error. Unfortunately, you have an abbreviated traceback. You won't get more information unless you alter your `ignition.conf` to include an additional option of `-XX:-OmitStackTraceInFastThrow` to avoid the abbreviation. (You'll have to restart the gateway for that to take effect. Then you can get a complete error report.)

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 26, 2023, 11:35pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/18 "2023-12-26T23:35:05Z")

</div>

Does it matter where in the file this change is made?

And, would I type it just as you did?

---

<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:** [December 26, 2023, 11:37pm UTC](https://forum.inductiveautomation.com/t/unable-to-compile-code-on-change-script/83485/19 "2023-12-26T23:37:04Z")

</div>

Put it in the group of "java.additional" lines, same format, with a unique numeric suffix before the equals sign.
