ZBrushCentral

ZScript Quick Tips: Language Features

Here’s a few things that might be helpful to someone starting out like me. They’re things I’m discovering on the way that I couldn’t find in the command refs.

  1. Variables are statically scoped within command groups defined by commands like IButton and RoutineDef. They don’t appear to be scoped within If and Loop blocks.

  2. Use the Val function to evaluate expressions that involve a combination of variables, numbers, and functions.

  3. I like to use a loop with an iteration count (not repeat count, that term is misleading since it implies that the loop will iterate at least once with a value of 0, when it doesn’t) of 1 and LoopExit when I need to perform to do a lot of comparisons. It can be useful for aiding readability since you can avoid nesting If statements a whole bunch. Ex:

 
[Loop, 1,
	[If, #id = 1, [VarSet, name, "Foo"][LoopExit] ]
	[If, #id = 2, [VarSet, name, "Bar"][LoopExit] ]
	[If, #id = 3, [VarSet, name, "Baz"][LoopExit] ]
	[If, #id = 4, [VarSet, name, "Qux"][LoopExit] ]
 
	// Else condition can be put here:
	[VarSet, name, "Other"]
] 

Such conventions are highly personal but I think this beats having to read write:

 
[If, #id = 1, [VarSet, name, "Foo"],
	[If, #id = 2, [VarSet, name, "Bar"],
		[If, #id = 3, [VarSet, name, "Foo"],
			[If, #id = 4, [VarSet, name, "Foo"],
				[VarSet, name, "Other"]
			]
		]
	]
]

Or something along those lines.

  1. Use # to dereference a variable (or evaluate it). Use it when referring to the value stored in a variable. Do not use it when referring to the variable itself by name as in the case with the [Var*] commands.