ZBrushCentral

maximum vardef per script

Hi, i have a true problem with the zscript limitation.
i can’t to figure out how to count the maximum of var that ca ben declared into a single Script.

i made a test plugin to make my tests.
the script has 256 Vardef, defined out of a routine scope, to make sure Zbrush create every var at the loading.

[VarDef, test01, “”]
[VarDef, test02, “”]
[VarDef, test03, “”]
etc…
[VarDef, test256, “”]

Well it works, but…
If I add one more var ( 257 ) the script will not run because the limitation has been reached, this is okay , but.
if I replace the 255 and 256 by this

[VarDef, test01, “”]
[VarDef, test02, “”]
[VarDef, test03, “”]
etc…
[VarDef, test255(50), “value”]
[VarSet, test255(49), “a value”]

It works and test255(49) or any var from the list, can return a value without any trouble.
255+50 = 305
Now i did that too for test254(50)
so i can access 355 variables.

But we don’t always have the need of using Varlist , i more in the need of using basic variable.

If a gather some statistics from my plugin, i can see that i use 202 vardef in the whole script process.
has we dont run all routine from the script the script can properlly get executed, without any error message about the maximum variable limit.
i got only 74 vardef declared,out of the routine scope.
every of them are single vardef, not varlist.
I already did a lot of optimization about the use of variable in my script, not avoid this limitation, i try to use more neutral var i just reset and reuse, like for filepath, don’t need to have dozen of variable with diffrent name to handle that.
some feature like function that snapshot the current setting before to run the render batch, so it can return to was it was before we run the render batch.

The most expensive functions that use a lot of Var in a list are the two following features:

UIStates routine, that handle the state of every switch buttons. it’s a vital function for the plugin. this varlist contain 84 states and use the MVarDef and MVarSet to handle restoring the ui state.
Save/load Project preferences, here is another varlist that grab different ui items status( switch and slider)and write the preference to a file, it contains 70 variable in the varlist. it not a MVarDef

74(global vars)+84(UiStates)+70(Preferences)=228 variables
i hold a counter in my script header, just to make sure i stay off the zscript limitations.
Also i can’t to tell how many other local vardef that are declared within the routine scope, gets cumulated with the global vardef and i must to maintain a certain distance from this limitation, so i mus to m ake sure every process , specifically those process which involve a lot of variable can run without a process breaking if it reachs the limits.

I try to delegate the Preference saving and loading to a different Zscript executed from my plugin ui, It works just as expected to Save the preference, i can also load the preferences read the varlist, but it’s impossible to apply any Ipress, Iset, Iclick, etc. to the main plugin.

example :

[RoutineDef, Main,
[Ipress/ISet/IClick, “Zplugin:myplugin:switch 1”]
[Ipress/ISet/IClick, “Zplugin:myplugin:switch 2”]
]
[RoutineCall, Main]

None are working, i tested with my plugin and with other plugin, sadly it worked with decimation master to enable two switch.
when i do that on my plugin, the switchs get all enabled, but the next second, every change disappear at once.

Removing the preference save and load to an independent zscript would had helped to remove a varlist of 70 entries, but i not sure it possible, this is intended to work with zbrush native functions but not with plugin i guess.

All the global vardef has been ultra optimized, i can’t to improve more without to make the script unreadable, i can’t to use local variables for the 74 global vardef.

for the 70 that hold the preferences save and load, i already moved the varlist to a local variable.

I am not sure how zbrush counts the max vars when varlist are involved. after refactoring the save/load preferences varlist to a local varlist, it just give me one more global vardef, not 70 more.

Understanding or tracking which are the Vardef that are counted everytime i hit any button of my plugin, is not that easy.

Note for the readers, hmm thx you for reading, i guess just a single man in the world can understand and read me well ;p
I look for advices, tips or having a better understanding of the way zbrush count the vardef.
Or the god way to enable my plugin switchs items from an independent zscripts process, would be very helpful too ;p

Best Regards,
Nicolas

Maybe a memory block, or two?

Doug sorry but i don’t understand your answer, Memory block are for persistent i just need it for the uistate.
All global/local variables get reset when the script ended having more memory block would not change anything to my problem.
for instance I don’t need persistent memory block for the preferences, which is a none sense if i would.
I just want to be able to register/declare more single var with vardef.

74 global variable declared with vardef is not enough to me.
why i can have 255 global var def + 50 +50 from the varlist
when it’s impossible to execute more that my 74 global combined local var defined into all my routines def.

feel like it could work to create the 253 global vars ( placeholder include) and subtract the Mvardef that seems to count Has One + the Preferences varlist, from this 255 global vars.

[VarDef, test01, “avalue”] //my global vars
[VarDef, test02, “anothervalue”]
[VarDef, test03, “”] //placeholder
[VarDef, test04, “”] //placeholder
etc…
[VarDef, test253, “”] //placeholder
[VarDef, test254, “”] //placeholder
//Varlists are the last Var to be registred…
[VarDef, preferences(70), “”]
//then the memoryblock creation and default setup if the file doesn’t exists…
[If,[MemGetSize,uiSwitchesState],

[If, [FileExists,uiStatesMem], [MemCreateFromFile,uiSwitchesState,uiStatesMem,] ,//else [MVarDef, uiSwitchesState,86,0] //Define Default Settings : // Preferences Slots [MVarSet, uiSwitchesState,0,1] // SLot1 [MVarSet, uiSwitchesState,1,0] // SLot2 [MVarSet, uiSwitchesState,2,0] // SLot3 //etc... ]

]

Is this could work ? I would have to also subtract the maximum amount of local value that will run depending of the routines that will be executed.

To be honest I’ve never paid much attention to the variable limit. I think I’ve encountered it but not for a while. I tend to use memory blocks whenever I need to save the UI state and things like transforms (using MTransformSet is preferable to using TransformSet anyway). I’ve no idea how list variables affect things or memory blocks declared using MVarDef (though I can’t see why they should affect it at all).

The limit itself seems rather arbitrary in that strings take up more memory than floats.

all right thank you to the answer Marcus
and about this problem :

I try to delegate the Preference saving and loading to a different Zscript executed from my plugin ui, It works just as expected to Save the preference, i can also load the preferences read the varlist, but it’s impossible to apply any Ipress, Iset, Iclick, etc. to the main plugin.

example :

[RoutineDef, Main,
[Ipress/ISet/IClick, “Zplugin:myplugin:switch 1”]
[Ipress/ISet/IClick, “Zplugin:myplugin:switch 2”]
]
[RoutineCall, Main]

None are working, i tested with my plugin and with other plugin, sadly it worked with decimation master to enable two switch.
when i do that on my plugin, the switchs get all enabled, but the next second, every change disappear at once.

Removing the preference save and load to an independent zscript would had helped to remove a varlist of 70 entries, but i not sure it possible, this is intended to work with zbrush native functions but not with plugin i guess.

Is there any magic command that could help me to reactivate my switchs buttons from the zscript ?

vardef string are more expensive than float ?
does it means this :
[Vardef, myvarlist(50), “”]
with store 50 *256 bytes ? even if the string is only one character (1bit)?

  1. You should enable all ISwitches at the end of your plugin code to make sure they stay enabled:

[IEnable,“Zplugin:My Plug:My Switch”]

And don’t try to use one plugin to communicate with another - sooner or later it will fail.

  1. Yes, floats take 4 bytes and strings up to 256 bytes.

[Vardef, myvarlist(50), “”]

will declare a list of 50 strings of up to 256 bytes each, though ZBrush probably only assigns the memory as needed.

And don’t try to use one plugin to communicate with another - sooner or later it will fail.

i don’t try to communicate, just activate the several switchs from another Zscript.
it works well for slider.
Also the uistate and the preference will collide together,

this is the way it declare my switch button :
[ISwitch, “Zplugin:zTexturer:Render Options:Flat”,
[MVarGet,t_uiSwitchesState,37]
,//pupop tooltip
“\CffffffEnable \Cff9923Albedo Map \CffffffBaking.”
,//grouped commands
[MVarSet,t_uiSwitchesState,37,1]
[RoutineCall,UIStateToFile]
,
[MVarSet,t_uiSwitchesState,37,0]
,0
,0.5
]
[IEnable, “Zplugin:zTexturer:Render Options:Flat”]

So what’s not working?