Ren'Py show animation (label) from another script

monkeyposter_7

Thirsty for my Guest
Game Developer
Nov 23, 2018
330
1,181
now im stuck on trying to make this

i basically want another separate file script "animations.rpy" to keep my main script clean as much as possible
and in that "animation" script i want to make many animations
Lets say "label animation1:" and so on

now, how to import this in main script?

so u are in main script, u choose option 1, and it shows "animation1" from "animation rpy" and when u click the mouse it continues in main script
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
To the best of my knowledge Ren'py doesn't care about what code you put in which files, it all works across the whole project unless you specify that it's local. Where you put the code is more about have an organization that you understand.
 

monkeyposter_7

Thirsty for my Guest
Game Developer
Nov 23, 2018
330
1,181
But now i have another problem

If i put two animations (anim1 and anim2 labels) it only loads the second (last one)

Code:
label test:
    scene 0000
    call animation1
    menu:
        "faster":
            call animation2
    jump endofgame

and here is animations.rpy, i think problem is here somewhere

Code:
label animation1:
    scene 0000
    image 0000:
        "0000.png"
        0.1
REMOVED OTHER IMAGES FOR FORUM
        repeat
label animation2:
    scene 0000
    image 0000:
        "0000.png"
        0.03
REMOVED OTHER IMAGES FOR FORUM
        repeat
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Do you pause at the end of the animation?

Code:
label animation1:
    scene 0000
    image 0000:
        "0000.png"
        0.1
REMOVED OTHER IMAGES FOR FORUM
        repeat
    pause
label animation2:
    scene 0000
    image 0000:
        "0000.png"
        0.03
REMOVED OTHER IMAGES FOR FORUM
        repeat
    pause
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
The problem is that the image command defines an image for you to use in your game. They are defined before your game starts, it doesn't matter where they are in the code.

Because you have the image '0000' defined twice, the last one defined is the one that sticks. So '0000' will always be the fast animation.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
So i used
call animation1 from animations
and it worked
Unless you are going to be very careful and organized, I'd avoid adding things like "from animations" yourself.

That "from animations" isn't "from animations.rpy"... it's just "from {uniquenamehere}".

As far as I know, each "from" needs to be unique. The RenPy build process includes a option for "add from clauses to calls" to do all the heavy lifting for you - and it's probably easier to let it keep track of all those unique names, than it is to do it yourself. Just don't add "from .... " yourself... and don't remove them either once the build process has already added them.

Just:
Python:
    call animation1
will be fine. Then switched on the option when you build.

The way I understand it, when you load a save game... it does some magic voodoo shit to figure out where you are up to within your game. AnneO'nymous has explained it for me in the past... and I'm sticking with "magic voodoo shit". It then goes to that line of code (or the nearest previous one it can figure out) and carries on, even if code around it has changed. It has a call/return stack to figure out where to return back to when it hits a return statement. Now in theory, you don't need the "from ...." at all, because of other magic voodoo shit. But to avoid confusion and to make sure the return statement goes back to where it should do... adding all those "from ...." clauses is a good idea - which is why the build process offers to do it all for you.

But as Epaddder says... RenPy really doesn't care where your label statements are or any other commands are. As the game starts, it loads everything in and sort it all out. That means you're fine with a single script.rpy or lots of separate .rpy files all over the place in different subfolders.
You don't even need a script.rpy file. What RenPy is looking for is a "label start:" statement. If that exists in wibble.rpy... that's where your game will start.

That's pretty much the reason why you can put "call my_label" in any .rpy file and "label my_label:" in any other.
 
  • Like
Reactions: monkeyposter_7

monkeyposter_7

Thirsty for my Guest
Game Developer
Nov 23, 2018
330
1,181
The problem is that the image command defines an image for you to use in your game. They are defined before your game starts, it doesn't matter where they are in the code.

Because you have the image '0000' defined twice, the last one defined is the one that sticks. So '0000' will always be the fast animation.

Yes! It worked when i changed second animation to 0001

But now i have another problem lol

when the first animation starts, and u click the mouse, it starts second animation right away. and then u get the choice for "faster"

I want it to be
animation1
mouse click - u get choice "faster" while animation1 is still playing
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
But now i have another problem

If i put two animations (anim1 and anim2 labels) it only loads the second (last one)

Code:
label animation1:
    scene 0000
    image 0000:
        "0000.png"
        0.1
REMOVED OTHER IMAGES FOR FORUM
        repeat
label animation2:
    scene 0000
    image 0000:
        "0000.png"
        0.03
REMOVED OTHER IMAGES FOR FORUM
        repeat
Carrying on looking at your code...

I'm going to guess the issue here is that you are defining "image 0000" twice.
You'd be better off with...

Python:
image 0000a1:
    "0000.png"
    0.1
    # REMOVED OTHER IMAGES FOR FORUM
    repeat
image 0000a2:
    "0000.png"
    0.03
    # REMOVED OTHER IMAGES FOR FORUM
    repeat

label just_another_label:
    scene 0000a1

    menu:
        "faster":
            scene 0000a2

    jump endofgame
EDIT: Multiple edits... because my fingers work quicker than my brain apparently. Maybe re-read @DMDfan69 .

each image is unique, but makes use of 0000.png (or whatever) multiple times.
Keep in mind that "image"s.... like "define"s and other statements can be setup anywhere in your code and within any .rpy file.
My names of 0000a1 and 0000a2 is just 0000 (animation 1) and 0000 (animation 2). Though maybe that 0000 prefix doesn't make sense now that I think about it. You could just use "image anim1:" and "image anim2:" instead... or whatever naming scheme makes sense to you.

If I've read your previous comments correctly (unlikely I know... even for me)... you don't need calls at all... just separate image statements for each of your animation speeds. And yes, I would put all those "image {name}:" statements in a separate .rpy file... like animations.rpy. (though I think I used sprites.rpy).
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
But now i have another problem

If i put two animations (anim1 and anim2 labels) it only loads the second (last one)

Code:
label test:
    scene 0000
    call animation1
    menu:
        "faster":
            call animation2
    jump endofgame
Maybe this will help, although I don't know the most elegant way to do it... I'm sorry, I don't use the "call" function in my animations.

Code:
label test:
    scene 0000
    call animation1
    menu:
        "faster":
            $ animation2 = True
            if animation2 == True:
                call animation2
    jump endofgame
 

monkeyposter_7

Thirsty for my Guest
Game Developer
Nov 23, 2018
330
1,181
Wait, now im coffused lol

We need to get back to the start of thread, my inisall question was how to make this. So (on my own) i figured i use the "call" option

I want to make animations.rpy where i will put all animations each under label
label anim1:
here goes the code for animation (its sequence of images that are looped)
label anim1faster:
here goes the code for animation
label anim2:
here goes the code for animation
label anim2faster:
here goes the code for animation

and then in my main script i can just use something like:

y "I would like that!"
call (or whatever) anim1
menu:
"faster":
call anim1faster
jump whatever
"stop:
jump stop


so, i might be going totally wrong about this since u guys are not even using this "call"
maybe something else?
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
Maybe this will help, although I don't know the most elegant way to do it... I'm sorry, I don't use the "call" function in my animations.

Code:
label test:
    scene 0000
    call animation1
    menu:
        "faster":
            $ animation2 = True
            if animation2 == True:
                call animation2
    jump endofgame
It's unnecessary if it is only an animation there is little point of placing it in a label. ;)

Anyway if I had to guess why the animation starts immediately is that at the end of the 'animation1' label you don't have a 'return' statement, so Ren'py just continues on to the label immediately below it. If you call a label you have to return from it.

It would probably be a lot easier just to do something like this:
Python:
image animationOneSlow:
    #### SLOW IMAGE SEQUENCE

image animationOneFast:
    #### FAST IMAGE SEQUENCE

label somesceneingame:
    scene animationOneSlow
    pause

menu animationOneChoice:
    "Faster":
        show animationOneFast
        pause
        jump nextsceneingame

label nextsceneingame:
    ### WHAT EVER HAPPENS AFTER THE ANIMATION
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Hmmm. I edited my original post so many times... I think I need to restate it to clarify.

Image statement can be in any .rpy file. They can be used anywhere else too. No need for calls.

So imagine this....

Python:
# animations.rpy

image anim1:
    "0000.png"
    pause 0.1
    "0001.png"
    pause 0.1
    "0002.png"
    pause 0.1
    repeat

image anim2:
    "0000.png"
    pause 0.03
    "0001.png"
    pause 0.03
    "0002.png"
    pause 0.03
    repeat
Python:
# script.rpy

label just_another_label:
    y "I would like that!"
    scene anim1
    y "oh baby, you're the best."
    pause

    menu:
        "faster":
            scene anim2
            y "oh my god!"
            pause
        "stop":
            pass
I think that's pretty much what you are looking for. Two animations, both containing the same images... but running at different speeds. With your animations and their associated list of image files are kept separate from your main script... just for neatness sake.
The "pass" is there just because no other action is required. It's effectively a "do nothing" command.

Edit: As Epaddder has put... you might need extra pause statement in there... just so the player has to click to continue. Alternatively you could have your characters speaking while the animation runs... or anything else that suits your needs.
 

monkeyposter_7

Thirsty for my Guest
Game Developer
Nov 23, 2018
330
1,181
@79flavors

So instead of using labels for animations, i should use image names?
and then in my main script if i want a animation to play, i just put in that name of the image (instead of label name)?
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
@79flavors

So instead of using labels for animations, i should use image names?
and then in my main script if i want a animation to play, i just put in that name of the image (instead of label name)?
Yup.

Either:
scene anim1:
-or-
show anim1:

RenPy doesn't care if your image is a single image... or an accumulation of lots of images. Including composite images.

Though @Epaddder got there quicker than I did (and remembered to include pauses so the player can watch the animations).
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
I will say that, you could need a label if you were going to do something more complicated with these animations.

If the animations and scene were being reused to track how many times you went 'faster' or if going 'faster' with a love interest affected your relationship in some way.

You're generally going to use 'call' on elements you want to reuse so that you don't have to constantly recreate them leading to hard to trace errors or just a massive headache if you decide to rework a mechanic in the game.
 
  • Like
Reactions: monkeyposter_7

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,964
16,206
Code:
label test:
    scene 0000
    call animation1
    menu:
        "faster":
            call animation2
    jump endofgame
Code:
label animation1:
    scene 0000
    image 0000:
        "0000.png"
        0.1
REMOVED OTHER IMAGES FOR FORUM
        repeat
label animation2:
    scene 0000
    image 0000:
        "0000.png"
        0.03
REMOVED OTHER IMAGES FOR FORUM
        repeat
You already had all the answer you need, except for one thing concerning this part.

You were misusing image. It's a statement that works at real init level. This mean that, when you write :
Code:
label animation1:
    scene 0000
    image 0000:
        "0000.png"
        0.03
What Ren'py see is :
Code:
label animation1:
    scene 0000

image 0000:
    "0000.png"
    0.03
So, two separate things.
 
  • Like
Reactions: monkeyposter_7