Is there a way to create macros with renpy? [SOLVED]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Is there a way to create macros with renpy? [SOLVED]

#1 Post by Frost Mage »

I checked the docs, but I did not see anything on creating macros in renpy. For example, if I have this code:

Code: Select all

	scene bg hall01
         with fade
         scene bg hall02
         with dissolve
         scene bg hall03
         with dissolve
is there a way I could just type halltransition in my script and have renpy replace the that with the above code?
Last edited by Frost Mage on Tue Mar 17, 2020 9:04 am, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is there a way to create macros with renpy?

#2 Post by Imperf3kt »

ATL, you'll require it. (The code you've written won't work as expected)
https://www.renpy.org/doc/html/atl.html?highlight=atl
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Re: Is there a way to create macros with renpy?

#3 Post by Frost Mage »

Thanks, that was what I was looking for in this case. Follow up question though, the following code does not trigger any errors, but the transition simply does not happen. I know it is getting called because I can see the print statement in the console when it is triggered, but nothing happens. Any ideas?

Code: Select all

image bg door01:
    print ("test")
    pause 1.0
    linear 0.5 alpha 0.0
    "bg door02"
    alpha 0.0
    linear 0.5 alpha 1.0
and I call it like this:

Code: Select all

show bg door01

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Is there a way to create macros with renpy?

#4 Post by Alex »

Try it like this may be...

Code: Select all

transform door01:
    print ("test")
    pause 1.0
    linear 0.5 alpha 0.0
    "bg door02"
    alpha 0.0
    linear 0.5 alpha 1.0

image bg door01:
    contains door01
https://www.renpy.org/doc/html/atl.html ... -statement

User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Re: Is there a way to create macros with renpy?

#5 Post by Frost Mage »

Hmmm, still no luck. Same behavior with that code. I will keep trying to isolate the problem. Is there anything else I could try

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is there a way to create macros with renpy?

#6 Post by Imperf3kt »

I've never heard of a print function in renpy, do you want to place text on the screen as an image?
You'd use text("my text") for that (Text in screens)
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Re: Is there a way to create macros with renpy?

#7 Post by Frost Mage »

No, I was just printing to the console to check if the ATL had been run. Here is some extra information I just discovered, if i run show bg door01 under label start, the screen fades from black to door02.

User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Re: Is there a way to create macros with renpy?

#8 Post by Frost Mage »

Okay, so I think I have narrowed down the problem. If I call show bg door right before a jump

Code: Select all

show bg door
jump a07
The scene associated with the new label will display over the door animation. If I flip the order, the door animation will play over the new background. What I want to have have happen is a simple door animation that plays in between scene transitions, but that can be skipped over by clicking.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is there a way to create macros with renpy?

#9 Post by Imperf3kt »

For That I suggest a call action.
The idea is you have a label that has nothing but the door animation in it, followed by a pause then a return.

When you want to jump to a new scene, and use the door animation, call the door animation label and then place a jump to wherever you are jumping.

Something like this

Code: Select all

    "Let's look at the door." 
    show door
    "alright, enough looking, let's go." 
    call door_anim
    jump through_the_door
    
label through_the_door:
    "By the gods, it's the other side of the door!"
    
    return
    
    
    
label door_anim:
    show door_animation_ATL
    pause
    return
    
You can skip the call and separate label if you only use this once or so. The label is just for convenience.


I'll post a working example in a couple of hours when I'm home.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Frost Mage
Newbie
Posts: 21
Joined: Fri Mar 13, 2020 7:38 pm
Contact:

Re: Is there a way to create macros with renpy?

#10 Post by Frost Mage »

Thank you so much! That was exactly what I needed. You all have been very helpful here, I really appreciate it. Here is the working code if anyone else has the same problem.

Code: Select all

transform door01:
    "bg door01" with fade
    0.5
    "bg door02" with dissolve

image bg door:
    contains door01

label opendoor:
    show bg door
    pause
    return
and to call it

Code: Select all

show bg door

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Is there a way to create macros with renpy? [SOLVED]

#11 Post by trooper6 »

Do you need both door images? What is the difference between them?

Anyhow, I'd just create a custom multiple transition. I tested this and this works for two different images:

Code: Select all

define doortrans = MultipleTransition([
    False, Dissolve (0.5),
    "Door1.jpg", Pause(0.5),
    "Door1.jpg", dissolve,
    "Door2.jpg", Pause(0.5),
    "Door2.jpg", dissolve,
    True])

label start:
    scene bg underpassday
    show joseph_1 at left
    j1 "Hello! It is day."
    scene bg underpassnight with doortrans
    show joseph_1 at left
    j "It should be night, and we should have gotten there with the door transition. Ta Da!"
    return

MultipleTransition is documented here: https://www.renpy.org/doc/html/transiti ... Transition
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Toma