ZBrushCentral

Recursive zscripting, a 'discovery'

Just to inform those who struggle to call a [IButton,button_x] from within this same button-script. So a recursive procedure.
As I noticed you canNOT do that like this:

[IButton, button_x,
//code:

[code1]
[If, (condition is true),
[do this]
,//else
//start with this IButton again:
[IPress, “button_x”]
]//end of if
//end of code
]

Instead, what does work is to put the whole codepart in a Routine and from within you CAN call the routine as often as you want:

[RoutineDef, RoutineButton_x,

//code:

[code1]
[If, (condition is true),
[do this]
,//else
//start with this IButton again:
[RoutineCall, “RoutineButton_x”, inputA,inputB]
]//end of if
//end of code

,inputA,inputB
]//end of routine

And the Button-script becomes:

[IButton, button_x,
//code:

[code1]
[VarSet, inputA,0]
[VarSet, inputB,0]
[If, (condition is true),
[do this]
,//else
//start with the RoutineCall:
[RoutineCall, “RoutineButton_x”,inputA,inputB]
]//end of if
//end of code
]

I hope that you find a use for this ‘discovery’

Happy Zscripting,
EddyL

this is nice but it only works two times and then I get an error…
or did I something wrong??

////////////////////////////

[RoutineDef,Endless,
[NoteIButton,[StrMerge,"Endless button ",A], 0 , 1 ,[IWidth,1008]/2, [IHeight,1000]/2 ,600,400 ,0.5 ,1, 0,1,0.5]
[NoteIButton,“Next”,0,0,50,0,40,50,0x242424,0xD3D3D3,0.7,0.5]
[NoteIButton,“Exit”,0,0,-50,0,40,50,0x242424,0xD3D3D3,0.7,0.5]
[VarSet,A,A+1]
[VarSet,Output,[Note,0,0,0]]
[If,Output=2,[RoutineCall,“Endless”,A]]
[If,Output=3,[Exit],[Exit]]
,A
]

[ISubPalette,“Zscript:MyMenu”]
[IButton, “Zscript:MyMenu:Endless”,
[VarSet,A,0]
[NoteIButton,[StrMerge,"Endless button ",A], 0 , 1 ,[IWidth,1008]/2, [IHeight,1000]/2 ,600,400 ,0.5,1, 0,1,0.5]
[NoteIButton,“Next”,0,0,50,0,40,50,0x242424,0xD3D3D3,0.7,0.5]
[NoteIButton,“Exit”,0,0,-50,0,40,50,0x242424,0xD3D3D3,0.7,0.5]
[VarSet,Output,[Note,0,0,0]]
[If,Output=2,[RoutineCall,“Endless”,A+1]]
[If,Output=3,[Exit],[Exit]]
]

////////////////////////////
what i want to do is just counting A up and reopen the noteButton again