Check if a variable is set Topic is solved

A forum dedicated to George scripting questions
Post Reply
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Check if a variable is set

Post by schwarzgrau »

I'm working on my second script, so I'm pretty new to GEORGE. I know some things about simple coding from php, javascript and python, but I still don't understand a lot of the basics in GEORGE, like how you check if a variable is set.

Code: Select all

TestArray[1] = 12
TestArray[2] = 24
TestArray[3] = 156

IF (TestArray[6] == TRUE)
	PRINT "TestArray is set"
ELSE
	PRINT "TestArray isnt set"
END
Obviously I didn't set TestArray[6], but how do I determine if it's set? I tried == TRUE, != ISSET, != NONE, != "", != EMPTY etc.
The weird thing is I can PRINT the variable, even if I never set it

Code: Select all

PRINT TestArray[6]
produces a window with testarray.6
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
NathanOtano
Posts: 1202
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Check if a variable is set

Post by NathanOtano »

Just replace your " == TRUE" by the default variable value you get (here TestArray.6), then when it"s set, unless your value name and your value could be are exactly the same, the condition will be automaticlly false. Does it suits your needs? :)
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Check if a variable is set

Post by schwarzgrau »

Unfortunately not. This was just an example. I'm writing a script which should merge two layers, but keep the image marks (something like your suggestion here). And it would work without checking if a variable is set, but it would be a bit more scripting, but a lot more to do for the script.

Code: Select all

//======= TOP LAYER GET INFOS =======//

tv_LayerInfo
PARSE result layerDisplay layerPosition layerOpacity layerName layerType layerStart layerEnd layerPrelighttable layerPostlighttable layerSelection

TLnum = layerPosition		
TLfirst = layerStart		
TLlast = layerEnd 			

tv_LayerGetID TLnum
TLid = Result 				



//======= TOP LAYER SAVE MARKS TO ARRAY =======//

Cpos = TLfirst

DO
	tv_LayerMarkGet 0 CPos
	CColor = Result

	TLarray[Cpos] = CColor			//------ Save marks to array TLarray

	Cpos = CPos +1
UNTIL (Cpos == TLlast)




//======= BOTTOM LAYER GET ID AND SELECT =======//

BLnum = TLnum + 1
tv_LayerGetID BLnum
BLid = result
tv_LayerSet BLid



//======= BOTTOM LAYER GET INFOS =======//

tv_LayerInfo
PARSE result layerDisplay layerPosition layerOpacity layerName layerType layerStart layerEnd layerPrelighttable layerPostlighttable layerSelection

BLfirst = layerStart
BLlast = layerEnd



//======= BOTTOM LAYER SAVE MARKS TO ARRAY =======//

Cpos = BLfirst

DO
	tv_LayerMarkGet 0 CPos
	CColor = Result

	BLarray[Cpos] = CColor			//------ Save marks to array BLarray

	Cpos = CPos +1
UNTIL (Cpos == BLlast)




//======= MERGE LAYERS ======

tv_LayerMerge TLid STAMP
tv_LayerKill TLid



//======= MERGE LAYER GET INFOS =======//

tv_LayerInfo					
PARSE result layerDisplay layerPosition layerOpacity layerName layerType layerStart layerEnd layerPrelighttable layerPostlighttable layerSelection

MLfirst = layerStart
MLlast = layerEnd



//======= MERGE LAYER SET COLORS =======//

Cpos = MLfirst

DO
	IF (TLarray[CPos] != 0)				//------ if Top Layer mark isn't 0 choose Top Layer mark
		ColorSet = TLarray[CPos]
	ELSE								//------ else choose Bottom Layer mark
		ColorSet = BLarray[CPos]
	END
	tv_LayerMarkSet 0 Cpos ColorSet		//------ set Color
	Cpos = Cpos+1

UNTIL (Cpos == MLlast)
This works if both layers share the same length, BUT if one of them is longer or shorter it fails, cause then I'm asking here for something in the array I never defined.

Code: Select all

IF (TLarray[CPos] != 0)
I could fill both arrays with empty numbers, but seems ridiculous to me.
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
Post Reply