Writting values on Click

Hi,

My goal is to change a tag value by clicking on a component in perspective. As a total beginner especially with scripting is there some sort of script I could use to assign with the onClick event and for instance click on a component that already has a tag assigned and set its value to 64 for instance?

Current script:

{ var tag = “{[default]Carrier States/Carrier_001}”

var carrier = VAL(tag);

if(carrier=="9")
{
    SET(tag ,0);
}
else
{
    SET(tag ,9);
}

P.S any suggestions for a beginner with scripting and syntax’s?
Many thanks
Alex

You need to check out www.inductiveuniversity.com, it is a free website of learning materials including scripting. Here is a link to Ignition Scripting Functions. Scripting is done in Jython language, which is pretty much python 2.7 with access to some java classes/methods.

	tagValue = system.tag.read('[default]Carrier States/Carrier_001').value

	if tagValue == 9:
		newValue = 0
	else:
		newValue = 9

        system.tag.write('[default]Carrier States/Carrier_001',newValue)

Perfect!Thanks