hoch.png

Guides

Storing Data In Actions

If multiple special actions hold the same target method, you will probably need a way to determine which action has actually been clicked. While you won't need this when just using static nodes, you will definitely run into this issue when creating more dynamic ones, so I had to come up with a solution.

If at some point you have multiple entries in special_actions that would point to the same method like that:

{'remove custom parameter input 1': {'method' : M(self.action_remove_parameter)}
 'remove custom parameter input 2': {'method' : M(self.action_remove_parameter)}}

because the user added some inputs through other actions for example, just extend these entries by the data attribute like that:

{'remove custom parameter input 1': {'method' : M(self.action_remove_parameter),
                                     'data' : 1},
 'remove custom parameter input 2': {'method' : M(self.action_remove_parameter)},
                                     'data' : 2}

and add a data parameter to the target method:

def action_remove_parameter(self, data):
    param_number = data
    ...

The data attribute in the special_actions dict can be anything that's serializable by JSON. The following special_actions dict would lead to the same result

{'remove custom parameter input 1': {'method' : M(self.action_remove_parameter),
                                     'data' : {'param number' : 1}},
 'remove custom parameter input 2': {'method' : M(self.action_remove_parameter)},
                                     'data' : {'param number' : 2}}

if you adapt your target method accordingly

def action_remove_parameter(self, data):
    param_number = data['param number']
    ...

The little checkpoint nodes in Ryven are a good example for the need of this data parameter in special_actions, as you can add as many exec outputs as you want to it in exec mode and you can remove them individually. Take a look at its implementation as reference.