# Script syntax error mismatched input "expcting Indent, \<string\>, 9,0

**URL:** <https://forum.inductiveautomation.com/t/script-syntax-error-mismatched-input-expcting-indent-string-9-0/98681>\
**Category:** Ignition\
**Created:** [November 15, 2024, 5:40pm UTC](https://forum.inductiveautomation.com/t/script-syntax-error-mismatched-input-expcting-indent-string-9-0/98681 "2024-11-15T17:40:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [November 15, 2024, 5:40pm UTC](https://forum.inductiveautomation.com/t/script-syntax-error-mismatched-input-expcting-indent-string-9-0/98681/1 "2024-11-15T17:40:56Z")

</div>

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if initialChange or previousValue.value is None:
		return
	# when value turn off
	
	if not currentValue.value and previousValue.value:
	
	#Tracking time and durations
start_time = None
duration = None
	
	# Get current time
	current_time = system.date.now()
	
	# Grab Opc Tags
	
	alarm_value = system.tag.readBlocking([default]DT Fault /Alarm).value
	station = system.tag.readBlocking([default]DT Fault /Station 4)
	 # get the description from alarm value to search the array
	Description = system.tag.readBlocking([default]DT Fault /StationAlarmArray/StationAlarmArray_[alarm_value]_/Description)
	
	# Alarm_value greater than 0 Start timers
	if alarm_value >= 1:
		if start_time is None:
			start_time = current_time
	else
		if start_time is not None
			end_time = current_time
			duration = system.date.secondsBetween(start_time, end_time)
			
	system.db.runPrepUpdate("""
		Insert INTO [dbo].[Dt_LH_Faults]
					([Date]
					,[station]
					,[alarm_value]
					,[Description]
					,[start_time]
					,[end_time]
					,[Duration])
				Values (GETDATE(),?,?,?,?,?,?)
				""",[Date,Station,Fault Idx, Fault Description,Start Time,End Time, Fault Duration], "CAL")

```

Can anyone help with the error and take a look to see if this is done right new to scripting thanks in advance

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 15, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/script-syntax-error-mismatched-input-expcting-indent-string-9-0/98681/2 "2024-11-15T17:58:23Z")

</div>

Python (and this forum) is sensitive to whitespace/indentation - it's how Python opens and closes "blocks" of code where other languages might use e.g. curly braces. Your `start_time` and `duration` variables are not indented at all, which means there's outside the scope of even the `valueChanged` function you're defining, which means they're not going to do anything. But that's a problem, because the previous semantic line, `if not currentValue.value and previousValue.value:` is _opening_ a new lexical scope.

If you're used to a C/Java/Javascript/etc style language, think of it as you've left an _open_ curly brace on the line with the `if`, but you're never closing it.

I would highly recommend a brief introductory Python course to get basic fundamentals of the syntax right.
