What's wrong with this if statement

what's the correct syntax for:
checking if the day of the week is 7 or more,
setting the valve of a variable to 0 if it is more than 6,
and adding 1 to that variable if it is 6 or less?

I know this code works without the 'if statement'.

2 things are wrong, your if statement syntax and your indentation. It may be worth your time to check out some intro to python videos or lessons to help get you started.

Additionally, there are system methods to pull the date, day of week, hour, etc from what is returned from system.date.now().

Your script should look like:

today = system.date.now()
DOW = system.date.getDayOfWeek(today)
hr = system.date.getHour24(today)
min = system.date.getMinute(today)
dowOffset = 0

if DOW > 6:
	dowOffset = 0
else:
	dowOffset = DOW + 1

system.tag.writeBlocking(
	["[Default]PC_Time_DOW","[Default]PC_Time_Hr", "[Default]PC_Time_Min"],[dowOffset, hr, min])
5 Likes

Most specifically, it looks like you've mixed up the expression language and Jython.

Also, I'm pretty sure your dowOffset conditional can be rewritten using the modulo operator.

3 Likes

Thanks for the help, this solves my problem! I'll keep looking into the languages.

I'm still lost on when specific languages are needed. expect the addition part, (Dow_Offset == Dow + 1) I have other 'if statements' on tags in this program that work using the format in the original post.

the "==" was part of me just trying everything i could think of.

Here's an approximation:
If it says 'script' somewhere on the window, it's jython, otherwise it's expressions.

3 Likes