PDA

View Full Version : Recursive zscripting, a 'discovery'



EddyLoonstijn
12-16-07, 07:43 AM
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