'm trying to get a script running when i pressed the button on my circuit which runs a motor, the script is tied to onActionPerformed event, but when I run it, it gives me this error. The tags are correct and inserted in the script correctly.
"Unable to run action 'component.onActionPerformed' on MotorControl@D/root/Button: code could not be compiled."
The code for this event is:
def runAction(self, event):
# Define the tag paths for motor control and motor running time
motorStatusTagPath = "[default]My_Tags/Motor_Status"
# Motor control tag (on/off)
runningTimeTagPath = "[default]My_Tags/Motor_RunningTime"
# Motor running time tag
# Read the current motor status (True = running, False = stopped)
currentMotorState = system.tag.readBlocking([motorStatusTagPath])[0].value
# Read the current motor running time
currentRunningTime = system.tag.readBlocking([runningTimeTagPath])[0].value
# Toggle the motor state (on/off)
system.tag.writeBlocking([motorStatusTagPath], [not currentMotorState])
# If the motor is running, increment the running time by 1 (you can adjust the increment value
as needed)
if not currentMotorState:
# If the motor is turned on
system.tag.writeBlocking([runningTimeTagPath], [currentRunningTime + 1])
# Increase running time
org.python.core.PySyntaxError
File "<function:runAction>", line 2
testTagPath = "[default]My_Tags/Motor_Status"
^
SyntaxError: mismatched input 'testTagPath' expecting INDENT
at org.python.core.ParserFacade.fixParseError(ParserFacade.java:95)
at org.python.core.ParserFacade.parse(ParserFacade.java:205)
at org.python.core.Py.compile_flags(Py.java:2269)
at com.inductiveautomation.ignition.common.script.ScriptManager.compileFunction(ScriptManager.java:899)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.compileFunctionSuper(ProjectScriptLifecycle.java:825)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.getOrCreateDelegate(ProjectScriptLifecycle.java:941)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.<init>(ProjectScriptLifecycle.java:932)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.compileFunction(ProjectScriptLifecycle.java:805)
at com.inductiveautomation.ignition.common.script.ScriptManager.compileFunction(ScriptManager.java:882)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.lambda$invoke$0(ScriptFunctionHelper.java:115)
at java.base/java.util.concurrent.atomic.AtomicReference.updateAndGet(Unknown Source)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:108)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:98)
at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:80)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)
at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)
at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
at java.base/java.lang.Thread.run(Unknown Source)
Ignition v8.1.47 (b2025022612)
Java: Azul Systems, Inc. 17.0.13
Your code line 2 says, motorStatusTagPath = "[default]My_Tags/Motor_Status"
Your error indicates that line 2 is, testTagPath = "[default]My_Tags/Motor_Status"
Which is it?
The error message indicates that you're missing an indent. This could mean that you've used a tab in some places and 4 × space characters in others.
Ok that's removed (just added that to test the button) but the new error is:
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "<function:runAction>", line 19, in runAction
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
at org.python.core.Py.TypeError(Py.java:234)
at org.python.core.PyObject._basic_add(PyObject.java:2091)
at org.python.core.PyObject._add(PyObject.java:2068)
at org.python.pycode._pyx7.runAction$1(<function:runAction>:19)
at org.python.pycode._pyx7.call_function(<function:runAction>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function___call__(PyFunction.java:474)
at org.python.core.PyFunction.__call__(PyFunction.java:469)
at org.python.core.PyFunction.__call__(PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:868)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:950)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:161)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:98)
at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:80)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)
at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)
at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException
Traceback (most recent call last):
File "<function:runAction>", line 19, in runAction
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
... 29 more
Ignition v8.1.47 (b2025022612)
Java: Azul Systems, Inc. 17.0.13
You'll need to repost the current code (with the comment and indent corrected) and tell us which is line 19. (In the original post line 19 is a comment.)
Highly likely that your timestamp tag either is null or you are reading the wrong path. system.tag.writeBlocking([runningTimeTagPath], [currentRunningTime + 1]) is likely the line that is causing the error but the true cause is that for some reason your currentRunningTime value is null instead of a number.
Post your modified code so we can confirm/review for other issues.