#Issue while playing scene.
35 messages · Page 1 of 1 (latest)
Right there in the video you can see the difference; in the video it's .playing = true but you did .play = true
he said it was the same, and if I use playing it doesn't work.
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
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.
this project has 6 animations for the enemies, and it's supposed to be random. What do I do?
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.
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
Remove the = true part. You're just calling a function, not assigning a value.
well, I said animation, but it isn't even moving
Now there's a different error
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())
I'll try this. I clicked the left icon but it didn't do anything
nope
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)
so I should probably replace sprite_frames for mob_types
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.
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.
How many animations do you have? .pick_random() does exactly as it says, it's picking a random one each time.
Six for that scene
it just plays the same one each time I run the scene
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.
I tried that too and same results
I can send another zip so you can check it by yourself
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.