ZBrushCentral

question: total subtools in tool

Hi

I have had difficulty to get the total amount of subtools when they change over time in a variable :

Scenario - You run the plugin script the total amount of subtools are stored in the variable. When you duplicate the subtool or make more subtools the variable assigned does not get overwritten even though I declare the variable again and ask the total of subtools again:

[IButton,tester,
[VarDef,toolCount,[SubToolGetCount] ]
[messageOk,toolCount]
] // end button

Pointing out how to force a refresh or what I am doing wrong will be of great help.
Thanks!

I found the solution, was just me staring at the screen to long:

The VarDef, and VarSet has two different functions and rightfully so.

Def is to define a a variable, I am assuming same concept as declaring the variable being a int or str and Set is than to set the variable to a certain amount. Maybe this is bad practice but also assuming one can skip def and use set from the start, depends a lot on the scenario your variable will be used I guess?

Thanks in any case hoping to post small plugin soon.

Yes, you should use [VarDef] to declare your global variables at the start of the zscript. If you use [VarDef] inside a button or routine then sometimes you can get unexpected results. So for local variables [VarSet] is generally all that is necessary. I say generally because you may find instances where declaring a local variable is a good idea.