When you want to make a branch with Random in PythonBox
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
pass
def onUnload(self):
pass
def onInput_onStart(self):
import random
num = random.randint(0, 1)
if num == 0:
self.onA()
else:
self.onB()
With this kind of implementation Tweak the code when you want to change the number of branches from two to three, Since you have to go from editing the box to increasing the output, Increase the output so that it will create a branch without permission.
import numpy
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
self.outputs = []
for attr in dir(self):
if callable(getattr(self, str(attr))) and "output" in str(attr):
self.outputs.append(attr)
def onUnload(self):
self.outputs = []
def onInput_onStart(self):
r = numpy.random.randint(0, len(self.outputs))
method = getattr(self, self.outputs[r])
method()
Entering a box from editing and increasing the output declares the box's methods. Use dir (self) to get the box properties during onLoad and Check if it can be executed with callable (whether it is a method), Append the method labeled output to self.outputs.
The method that appends to self.outputs is executed by onInput_onStart.
Recommended Posts