Layer Opacity toggle

A forum dedicated to George scripting questions
Post Reply
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Layer Opacity toggle

Post by Zetariver »

Hello.I found this topic and am trying to customize it.
http://forum.tvpaint.com/viewtopic.php?f=21&t=6526" onclick="window.open(this.href);return false;
I want to toggle opacity 100% 50% and 25%.
And if layer opacity is not 100%, 50% or 25%, it changes it to 100%.

This works fine

tv_LayerDensity
LayerD = result
IF CMP(LayerD, "100")
tv_LayerDensity 50
ELSE
IF CMP(LayerD, "49")
tv_LayerDensity 25
END
IF CMP(LayerD, "24")
tv_LayerDensity 100
END
END

but, I don't know how to make another Else clause that checks if layer opacity is not 100%,50% and 25%.
What should I do?

I thought this will work, but it didn't. it only changes layer opacity to 100%.

tv_LayerDensity
LayerD = result
IF CMP(LayerD, "100")
tv_LayerDensity 50
ELSE
IF CMP(LayerD, "49")
tv_LayerDensity 25
END
IF CMP(LayerD, "24")
tv_LayerDensity 100
END
tv_LayerDensity 100
END
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Layer Opacity toggle

Post by Mads Juul »

Here is some different ways

#1 Using EXIT script command

Code: Select all


tv_LayerDensity
LayerD = result
IF CMP(LayerD, "100") 
	tv_LayerDensity 50
ELSE 
	IF CMP(LayerD, "49") 
		tv_LayerDensity 25
		EXIT
	END
	IF CMP(LayerD, "24") 
		tv_LayerDensity 100
		EXIT
	END
	tv_LayerDensity 100
END
#2 nesting conditional test correctly in If Else

Code: Select all


tv_LayerDensity
LayerD = result

IF CMP(LayerD, "100")
	tv_LayerDensity 50
ELSE 
	IF CMP(LayerD, "49") 
		tv_LayerDensity 25
	ELSE
		IF CMP(LayerD, "24") 
			tv_LayerDensity 100
		ELSE
			tv_LayerDensity 100
		END
	END
END
#3Tjeck first with &&(AND) if density is not 100 49 0r 25

Code: Select all

tv_LayerDensity
LayerD = result

IF CMP(LayerD, "100") == 0 &&  CMP(LayerD, "49") == 0 && CMP(LayerD, "24") ==0
	tv_LayerDensity 100
ELSE 
	
	
	IF CMP(LayerD, "100") 
		tv_LayerDensity 50
	END
	IF CMP(LayerD, "49") 
		tv_LayerDensity 25
	END
	IF CMP(LayerD, "24") 
		tv_LayerDensity 100
	END
END

Kind Regards Mads
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Layer Opacity toggle

Post by Zetariver »

All works fine! thank you Mads.
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Layer Opacity toggle

Post by Mads Juul »

you're welcome
User avatar
Animark
Posts: 505
Joined: 16 Oct 2008, 15:26
Location: Berlin

Re: Layer Opacity toggle

Post by Animark »

Very helpful scripts! Thanks a lot :-).
TVPaint 10.5.7 - Win10/64
TVPaint 11.0.8 - Win10/64
TVPaint 11.0.8 - Win10/64 (Wacom Companion 2)
Post Reply