#Issue while playing scene.

35 messages · Page 1 of 1 (latest)

fathom merlin
frozen river
#

Right there in the video you can see the difference; in the video it's .playing = true but you did .play = true

fathom merlin
#

I'm using Godot 4, he's using Godot 3 I believe

#

the think is that it was working before and now it isn't

frozen river
#

Ah. In Godot 4 .play is a function here, and you pass it a string with the name of the animation you want to play.

fathom merlin
#

this project has 6 animations for the enemies, and it's supposed to be random. What do I do?

frozen river
#

You could move the .play() call until after you assign the animation, and then not pass a string in. If you don't pass anything in it will resume whatever animation it is currently playing - the one that you just directly assigned it.

#

Alternatively, you could pick a random animation and then just pass that into the .play() call, potentially shortening all 3 lines into a single line.

fathom merlin
#

I'll try a single animation to see if it works

#

It opens now but

#

it says that now, and no matter what animation I select it just shows one of them

frozen river
#

Remove the = true part. You're just calling a function, not assigning a value.

fathom merlin
#

well, I said animation, but it isn't even moving

fathom merlin
#

Now there's a different error

frozen river
#

That's not an error, that's a breakpoint. You told it to pause on that line. Just remove the breakpoint by clicking on the icon to the left of the number.

#

Here, I believe this line should randomly pick one of the animations and play it, replacing all 3 lines you have there.

$AnimatedSprite2D.play(Array($AnimatedSprite2D.sprite_frames.get_animation_names()).pick_random())
fathom merlin
frozen river
#

That one line should replace all 3, not just the first.
(And the reason that it's complaining there is that frames was renamed to sprite_frames, as in that line I made)

fathom merlin
#

so I should probably replace sprite_frames for mob_types

frozen river
#

You shouldn't need that variable at all. The line I gave you already picks a random animation and plays it.

#

$AnimatedSprite2D.sprite_frames.get_animation_names() is just getting the list of animation names, like you were doing (but with the one rename so it works in 4.0), then I make it into an array by wrapping it in Array(), so I can add .pick_random() to choose a random name.

fathom merlin
#

Alr, it's "working" now with your line, so we got some progress, but it doesn't pick a random animation; it keeps to the same one even after closing and opening the scene.

frozen river
#

How many animations do you have? .pick_random() does exactly as it says, it's picking a random one each time.

fathom merlin
#

it just plays the same one each time I run the scene

frozen river
#

Very interesting results I'm getting here; try removing the randomize() call. In theory it should be doing nothing, but my testing seems to suggest that it's somehow de-randomizing, causing pick_random to always choose the same one.

fathom merlin
#

I can send another zip so you can check it by yourself

frozen river
#

I have to go now, but I could definitely check it when I get back, yes. In the meantime you might try extracting the name picking part and printing that to the console, see if that's the problem.

fathom merlin
#

Ok, idk what I did but it works now with your line

#

So ig it was a success?