[Solved]Repeating full block of code in hbox

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
ZianRiyone
Newbie
Posts: 11
Joined: Mon Jun 14, 2021 3:25 pm
Contact:

[Solved]Repeating full block of code in hbox

#1 Post by ZianRiyone »

What i want to do is that, exactly repeating whole block of code not one by one in hbox.

Here is my code:

Code: Select all


transform btn_trans_1_up:
    on show:
        linear 1.0 ypos -775
    on hide:
        linear 1.0 ypos 0

transform btn_trans_1_down:
    on show:
        linear 1.0 ypos 0
    on hide:
        linear 1.0 ypos -775

transform btn_trans_2_down:
    on show:
        linear 1.0 ypos 350
    on hide:
        linear 1.0 ypos 0

transform btn_trans_2_up:
    on show:
        linear 1.0 ypos 0
    on hide:
        linear 1.0 ypos 350

define btn_trans_1_check = False


screen choice_2():
    ##hbox: / from here ##
    showif btn_trans_1_check == True:
        add "images/Tutorial/Choice/[concept]/choice_window_alt.png" at btn_trans_2_down
        add "images/Tutorial/Choice/[concept]/choice_window_4.png" at btn_trans_1_up
        add "images/Tutorial/Choice/[concept]/2.png" at btn_trans_2_down
        imagebutton:
            at btn_trans_1_up
            idle "images/Tutorial/Choice/[concept]/1.png"
            action SetVariable("btn_trans_1_check",False)
    else:
        add "images/Tutorial/Choice/[concept]/choice_window_alt.png" at btn_trans_2_up
        add "images/Tutorial/Choice/[concept]/choice_window_4.png" at btn_trans_1_down
        add "images/Tutorial/Choice/[concept]/2.png" at btn_trans_2_up
        imagebutton:
            at btn_trans_1_down
            idle "images/Tutorial/Choice/[concept]/1.png"
            action SetVariable("btn_trans_1_check",True)
    add "images/Tutorial/Choice/[concept]/choice_frame.png"
i can write all 4 of them but i want something neat, usable and flexible.
Maybe using grid may help but i dont know.
Is there a code that will act as a bag and cover all this block code. If there is, I think it will be enough to repeat it 4 times. When I try for Frame, Viewport and Fixed, the transforms do not work. Please enlighten me.
Last edited by ZianRiyone on Tue Mar 05, 2024 9:24 am, edited 1 time in total.

User avatar
ZianRiyone
Newbie
Posts: 11
Joined: Mon Jun 14, 2021 3:25 pm
Contact:

Re: Repeating full block of code in hbox

#2 Post by ZianRiyone »

Okey okey i solved thath, fu... casue i defined the variable not default it.

jeffster
Veteran
Posts: 447
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: [Solved]Repeating full block of code in hbox

#3 Post by jeffster »

ZianRiyone wrote: Tue Mar 05, 2024 8:16 am What i want to do is that, exactly repeating whole block of code not one by one in hbox.

Here is my code:
You can also do it like this:

Code: Select all

default btn_trans_1_check = False
define btn_trans_1 = {
    False: btn_trans_1_down,
    True: btn_trans_1_up,
}
define btn_trans_2 = {
    False: btn_trans_2_up,
    True: btn_trans_2_down,
}

screen choice_2():
    add "images/Tutorial/Choice/[concept]/choice_window_alt.png" at btn_trans_2[btn_trans_1_check]
    add "images/Tutorial/Choice/[concept]/choice_window_4.png" at btn_trans_1[btn_trans_1_check]
    add "images/Tutorial/Choice/[concept]/2.png" at btn_trans_2[btn_trans_1_check]
    imagebutton:
        at btn_trans_1[btn_trans_1_check]
        idle "images/Tutorial/Choice/[concept]/1.png"
        action ToggleVariable("btn_trans_1_check")
    add "images/Tutorial/Choice/[concept]/choice_frame.png"
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

User avatar
ZianRiyone
Newbie
Posts: 11
Joined: Mon Jun 14, 2021 3:25 pm
Contact:

Re: [Solved]Repeating full block of code in hbox

#4 Post by ZianRiyone »

jeffster wrote: Tue Mar 05, 2024 10:02 am
ZianRiyone wrote: Tue Mar 05, 2024 8:16 am What i want to do is that, exactly repeating whole block of code not one by one in hbox.

Here is my code:
You can also do it like this:

Code: Select all

default btn_trans_1_check = False
define btn_trans_1 = {
    False: btn_trans_1_down,
    True: btn_trans_1_up,
}
define btn_trans_2 = {
    False: btn_trans_2_up,
    True: btn_trans_2_down,
}

screen choice_2():
    add "images/Tutorial/Choice/[concept]/choice_window_alt.png" at btn_trans_2[btn_trans_1_check]
    add "images/Tutorial/Choice/[concept]/choice_window_4.png" at btn_trans_1[btn_trans_1_check]
    add "images/Tutorial/Choice/[concept]/2.png" at btn_trans_2[btn_trans_1_check]
    imagebutton:
        at btn_trans_1[btn_trans_1_check]
        idle "images/Tutorial/Choice/[concept]/1.png"
        action ToggleVariable("btn_trans_1_check")
    add "images/Tutorial/Choice/[concept]/choice_frame.png"
Thanks a lot, its better

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]