Forum Archive

TypeError: Expected an Action object

Bjucha

Hello.
Does anybody know why I get a TypeError, when using repeat_forever method for scene.Action? If I use sequence instead it works, but I would really like to use repeat_forever.

Here is the part of the code:

blasers = SpriteNode('spc:LaserRed9' , parent=self)
        blasers.position = twinboss.position + (0, 30)
        blasers.z_position = -1
        b = random.uniform(10.0, 250)
        actions = [A.move_to(b, 100, 2 * 1), A.remove()]                                                    
        blasers.run_action(A.repeat_forever(actions))
        self.blasers.append(blasers)

But if I use:

blasers = SpriteNode('spc:LaserGreen13' , parent=self)
        blasers.position = twinboss.position + (0, 30)
        blasers.z_position = -1
        b = random.uniform(10.0, 250)
        actions = [A.move_to(b, 100, 2 * 1), A.remove()]                                                    
        blasers.run_action(A.sequence(actions))
        self.blasers.append(blasers)

It works fine, happy for any help...

JonB

repeat_forever takes an Action. You could generate a composite action, consisting of a sequence, then repeat that forever... though how would you repeat a remove()?

Bjucha

@JonB hmm I thought that I just could replace sequence with repeat_forever, but are you saying that remove method can not be there?
Gonna try it and se if I can get it to work

JonB

Remove removes the action, so that it's not what you want. You can define a sequence, then have that repeat:

A.repeat_forever(A.sequence(A.move_to(startpos), A.fade_to(1), A.move_to(endpos), A.fade_to(0)))

You can play with durations,etc, but here I move to the starting position, then unfade, then move to ending position, then fade out.

You can also define an action which calls a method, so can do more complicated things...

Bjucha

@JonB Ah, I have been looking at it from the wrong way. I thought A.repeat_forever came after, It still does not work perfectly but At least im not getting the Type Error anymore
Thank you man, gonna see if I can get it to work as I want it to now

Bjucha

Hmm still cant get it to work right.

I thought this would work:
```
blasers = SpriteNode('spc:BoltSilver' , parent=self)
blasers.position = twinboss.position + (0, 30)
blasers.z_position = -1
b = random.uniform(10.0, 250)
actions = [A.move_to(b, 10, 2 * 1),Action.remove()]

    blasers.run_action(A.repeat_forever(A.sequence(actions)))```

But the action does not repeat, I thought that A.repeat_forever would loop actions, but is only runs once

What am I missing?

JonB

You cannot have an Action.remove() in a list of actions to repeat forever!

Bjucha

@JonB But if I don’t use Action.Remove, the SpriteNode will not disappear, Since this is ”Laser” shot by an other SpriteNode I want them to move to a position then disappear and then the repeated. I thought that that the Action.Repeat_forever would run the whole process of the actions phase over and over again.

If I can’t use Action.remove() how can I make it work as I wanted?

JonB

@Bjucha said:

@JonB But if I don’t use Action.Remove, the SpriteNode will not disappear, Since this is ”Laser” shot by an other SpriteNode I want them to move to a position then disappear and then the repeated. I thought that that the Action.Repeat_forever would run the whole process of the actions phase over and over again.

If I can’t use Action.remove() how can I make it work as I wanted?

Did you see my pseudo code a few posts back? I tried to answer that..., what you want is to set fade to zero to"hide" the laser. Then move it to the starting position. Then fade to 1 to show it. Then"shoot" it, moving it to the ending position. Then fade to 0 again. Repeat that sequence forever.

Probably the alpha steps would have a 0 duration, so they happen immediately, only the actual "shot" would have a duration >0.

Bjucha

@JonB hmm, Im starting to understand it now thanks to you. Gonna see if I can get it to work,

Bjucha

@JonB I got it to work! But I do still have one question, Can the start position update? As of now it looks like this:

blasers = SpriteNode('spc:LaserRed15' , parent=self)
        blasers.z_position = -1
        a,b = boss.position



        blasers.run_action(A.repeat_forever(A.sequence(A.move_to(a,b), A.fade_to(1), A.move_to(10,10), A.fade_to(0))))

The problem is that the boss moves, so I though that by using a,b = boss.position I thought it would update, but it does not It will only use the boss first position so whe the boss moves the laser remains.

JonB

Since you are repeating forever, your code would always start from the same point (a and b a to b just numbers, not s pointer to some changeable value)

Probably what you need to do is have a custom function which gets called in the sequence, which sets the initial position. Iirc, Action.call let's you call a custom function.

Bjucha

@JonB Thank you, gonna se if I can xome up with some kind of function to be called