Base condition expression not working

Ignition 7.9.11,
I need do this python code in expression and get 1 (no_comm alway 1 for test) but sometimes I get 0 as result.

python code:

if no_comm:
	x=1
else:
	if not auto and not half_auto:
		x=0
	else
		x=1
return x

in expression:

if(no_comm,1,if(!auto && !half_auto,0,1))

table of variables and output of expression:
image

What is a wrong this expression?
Thanks.

if not auto and not half_auto:

However, if this is the truth table you are trying to replicate, it doesn’t matter what the state of half_auto is.

if no_comm:
	if not auto:
		x = 1
	else:
		x = 0
else:
	x = 0 

Hi,
I fixed python code (it’s for idea, thanks), the main question is what the problem with this expression?
I must check half_auto because it’s another opc tag in the system.
if auto and half_auto equals 0 so I need return 0 (it’s for alarm)
no_comm check connection, so I must check connection before display alarm.

Thanks.

It’s because the && operator does not exist in python.

http://www.ibiblio.org/g2swap/byteofpython/read/operator-precedence.html

Hi,
I don’t speak about python.
please look at the expression code.
Thanks.

Ah. I misunderstood your original post, my apologies. I have a meeting to run to, but I will post something in a bit.

Based on the expression you have here is the full truth table. Let me know what outputs you’re looking for.
image

You don’t need if at all, you can directly translate the logic from Jordan’s earlier post to an expression:
{Root Container.Group.NoComm.selected} && !{Root Container.Group.Auto.selected}
image

Had a chance to mock up your script to generate the truth table. It matches what would come out of your expression.

headers = ['no_comm', 'auto', 'half_auto', 'x']
data = []

for i in range(8):
	no_comm, auto, half_auto = [int(c) for c in format(i, 'b').zfill(3)]
	
	if no_comm:
		x = 1
	else:
		if not auto and not half_auto:
			x = 0
		else:
			x = 1
	data.append([no_comm, auto, half_auto, x])

util.printDataSet(system.dataset.toDataSet(headers, data))
row | no_comm | auto | half_auto | x
------------------------------------
0   | 0       | 0    | 0         | 0
1   | 0       | 0    | 1         | 1
2   | 0       | 1    | 0         | 1
3   | 0       | 1    | 1         | 1
4   | 1       | 0    | 0         | 1
5   | 1       | 0    | 1         | 1
6   | 1       | 1    | 0         | 1
7   | 1       | 1    | 1         | 1

So, I’d say that, if both truth tables match and the truth table layout matches what you’re looking for (still need confirmation of that), then it should be okay-- although it could be shortened to

no_comm || auto || half_auto

Let me know if the table is correct, or what rows should be different.