Forum Archive

Action.call() bugged for callables expecting parameters ?

zipit

Hi,

I cannot figure out how to use Action.call() properly on a function/ method that does expect the node and progress parameter as described in the docs.

When I do implement the following:

    def do(node, progress):
       pass

    SomeNode.run_action(Action.call(do), 1)

The debugger complains that the second parameter (duration) is not a string (which is a bit weird) and also that do() is being called passing no parameters while it does expect two parameters. The following snippet shows that do() is being called but without node and duration being passed.

def do(self, *args, **kwargs):
    print(1)
    print (args)
    print (kwargs)

SomeNode.run_action(Action.call(do), str(1))

What am I doing wrong ? I have not found any examples of Action.call() for a callable that does expect parameters here on the forums and I do not understand the docs (or the docs are wrong/ the method is buggy). Thanks for your help.

Cheers,
zipit

Edit: Actual code, I am using a custom node class, which might matter.

from scene import *
from ui import Path
import Data as d
import random


class BaseTile(Node):
    '''Draws a rounded rectangle.
    '''
    def __init__(self, size, color, position=(0,0)):
        self.path = Path.rounded_rect(0.0,
                                      0.0,
                                      size[0], 
                                      size[1], 
                                      d.tile_corner_radius)
        self.position = position
        self.add_child(ShapeNode(self.path, color))


class NumericTile(BaseTile):
    '''Draws a number on top of the BaseTile based on
    its value field. Also handdles its background color.
    based on its value and its size.
    '''
    def __init__(self, position, indices):
        self.vid = random.randrange(d.tile_maxpower_new)
        super().__init__(d.tile_size, 
                         d.colors[0]['tile_bg'][self.vid], 
                         position)
        self.indices = indices
        self.value = d.tile_values[self.vid]
        self.number = LabelNode('', (d.tile_font,40))
        self.number.color = d.colors[0]['tile_fg']
        self.add_child(self.number)
        self.SetText()
        self.run_action(
            Action.call(self.AnimationAddNode), str(1))

    def SetText(self):
        self.number.text = '{0}'.format(self.value)


    def AnimationAddNode(self, *args, **kwargs):
        print(1)
        print (args)
        print (kwargs)
omz

@zipit The duration of the action needs to be passed to the Action.call method, not to run_action. The reason it's complaining about 1 not being a string is that the second parameter of run_action is an optional key parameter (in short, it can be used to remove an action later).

So the code should be something like:

some_node.run_action(Action.call(do, 1.0))
zipit

Doh. Stupid me. Thanks for the quick help.

Cheers.