Question on Screen Call.

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
Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

Question on Screen Call.

#1 Post by Love&Peace »

Hi there.

I'm making [Block Puzzle Level Maker] with Ren'py for my company's business.

In this program, there are image buttons for blocks.
As follow:
screenshot0001.png
And if you click any button, you can see
screenshot0002.png
Let's suppose you click the top-left button.
Then the same block appears. And you can drag and drop it as you want.
screenshot0003.png
But there is a problem.
If any block is in frame, I cannot load the same block.
The other blocks are loaded normally but, the same block cannot be loaded.


I wrote my script like this.
<define image -> make a screen and add the image -> when user click the button, show screen>

I wrote my whole script. I need your help... :cry:

image.rpy

Code: Select all

image one:
    "one.png"
image two_01:
    "two_01.png"
image two_02:
    "two_02.png"
image two_03:
    "two_03.png"
image two_04:
    "two_04.png"
image three_01:
    "three_01.png"
image three_02:
    "three_02.png"
image three_03:
    "three_03.png"
image three_04:
    "three_04.png"
image b1_01:
    "b1_01.png"
image b1_02:
    "b1_02.png"
image b1_03:
    "b1_03.png"
image b1_04:
    "b1_04.png"
image b2_01:
    "b2_01.png"
image b2_02:
    "b2_02.png"
image b2_03:
    "b2_03.png"
image b2_04:
    "b2_04.png"
image b3_01:
    "b3_01.png"
image b3_02:
    "b3_02.png"
image b3_03:
    "b3_03.png"
image b3_04:
    "b3_p4.png"
image b4_01:
    "b4_01.png"
image b4_02:
    "b4_02.png"
image b4_03:
    "b4_03.png"
image b4_04:
    "b4_04.png"
image b5_01:
    "b5_01.png"
image b5_02:
    "b5_02.png"
image b5_03:
    "b5_03.png"
image b5_04:
    "b5_04.png"
image b6_01:
    "b6_01.png"
image b6_02:
    "b6_02.png"
image b6_03:
    "b6_03.png"
    "b6_04.png"
image b7_01:
    "b7_01.png"
image b7_02:
    "b7_02.png"
image b7_03:
    "b7_03.png"
image b7_04:
    "b7_04.png"
image b8_01:
    "b8_01.png"
image b8_02:
    "b8_02.png"
image b8_03:
    "b8_03.png"
image b8_04:
    "b8_04.png"
image b9_01:
    "b9_01.png"
image b9_02:
    "b9_02.png"
image b9_03:
    "b9_03.png"
image b9_04:
    "b9_04.png"
image b10_01:
    "b10_01.png"
image b10_02:
    "b10_02.png"
image b10_03:
    "b10_03.png"
image b10_04:
    "b10_04.png"
image b11_01:
    "b11_01.png"
image b11_02:
    "b11_02.png"
image b11_03:
    "b11_03.png"
image b11_04:
    "b11_04.png"
image b12_01:
    "b12_01.png"
image b12_02:
    "b12_02.png"
image b12_03:
    "b12_03.png"
image b12_04:
    "b12_04.png"
image cross:
    "cross.png"
image two_ver:
    "two_ver.png"
image two_hor:
    "two_hor.png"
image three_ver:
    "three_ver.png"
image three_hor:
    "three_hor.png"
image four_ver:
    "four_ver.png"
image four_hor:
    "four_hor.png"
image grid:
    "grid.png"
    xpos 137 ypos 137
image bg:
    "bg.png"
image bg_white:
    "bg_white.png"
image screenshot:
    "screenshot.png"
    xpos 53 ypos 1201
screen_capture.rpy

Code: Select all

screen keymap_screen:
    key "s" action Screenshot()

script.rpy

Code: Select all

show screen keymap_screen



label start:

    jump level_maker
    
label level_maker:
    call screen level_maker

level_maker.rpy

Code: Select all

screen level_maker:
    tag menu
    add "bg_white"
    add "grid"
    
    imagebutton idle "b1_button.png" hover "b1_button.png" action Show("block1_choose") xpos 102 ypos 40
    imagebutton idle "b2_button.png" hover "b2_button.png" action Show("block2_choose") xpos 227 ypos 40
    imagebutton idle "b3_button.png" hover "b3_button.png" action Show("block3_choose") xpos 374 ypos 40
    imagebutton idle "b4_button.png" hover "b4_button.png" action Show("block4_choose") xpos 548 ypos 40
    imagebutton idle "b5_button.png" hover "b5_button.png" action Show("block5_choose") xpos 665 ypos 40
    imagebutton idle "b6_button.png" hover "b6_button.png" action Show("block6_choose") xpos 765 ypos 40
    imagebutton idle "b7_button.png" hover "b7_button.png" action Show("block7_choose") xpos 865 ypos 40
    imagebutton idle "b8_button.png" hover "b8_button.png" action Show("block8_choose") xpos 965 ypos 40
    imagebutton idle "b9_button.png" hover "b9_button.png" action Show("block9_choose") xpos 1065 ypos 40
    imagebutton idle "b10_button.png" hover "b10_button.png" action Show("block10_choose") xpos 31 ypos 187
    imagebutton idle "b11_button.png" hover "b11_button.png" action Show("block11_choose") xpos 21 ypos 332
    imagebutton idle "b12_button.png" hover "b12_button.png" action Show("block12_choose") xpos 21 ypos 457
    imagebutton idle "one_button.png" hover "one_button.png" action Show("one") xpos 1205 ypos 181
    imagebutton idle "two_button.png" hover "two_button.png" action Show("two_choose") xpos 1190 ypos 280
    imagebutton idle "twobytwo_button.png" hover "twobytwo_button.png" action Show("twobytwo_choose") xpos 1173 ypos 395
    imagebutton idle "three_button.png" hover "three_button.png" action Show("three_choose") xpos 1173 ypos 527
    imagebutton idle "threebythree_button.png" hover "threebythree_button.png" action Show("threebythree_choose") xpos 1167 ypos 666
    imagebutton idle "four_button.png" hover "four_button.png" action Show("four_choose") xpos 16 ypos 550
    imagebutton idle "cross_button.png" hover "cross_button.png" action Show("cross") xpos 20 ypos 683
    
    add "screenshot"
    
    imagebutton idle "reset_idle.png" hover "reset_hover.png" action Jump("level_maker") xpos 845 ypos 1186
    imagebutton idle "exit_idle.png" hover "exit_hover.png" action Quit(confirm=True) xpos 1116 ypos 1186

        
        
    
screen b1_01:
    drag:
        add "b1_01"
screen b1_02:
    drag:
        add "b1_02"
screen b1_03:
    drag:
        add "b1_03"
screen b1_04:
    drag:
        add "b1_04"

screen b2_01:
    drag:
        add "b2_01"
screen b2_02:
    drag:
        add "b2_02"
screen b2_03:
    drag:
        add "b2_03"
screen b2_04:
    drag:
        add "b2_04"

screen b3_01:
    drag:
        add "b3_01"
screen b3_02:
    drag:
        add "b3_02"
screen b3_03:
    drag:
        add "b3_03"
screen b3_04:
    drag:
        add "b3_04"
        
screen b4_01:
    drag:
        add "b4_01"
screen b4_02:
    drag:
        add "b4_02"
screen b4_03:
    drag:
        add "b4_03"
screen b4_04:
    drag:
        add "b4_04"

screen b5_01:
    drag:
        add "b5_01"
screen b5_02:
    drag:
        add "b5_02"
screen b5_03:
    drag:
        add "b5_03"
screen b5_04:
    drag:
        add "b5_04"

screen b6_01:
    drag:
        add "b6_01"
screen b6_02:
    drag:
        add "b6_02"
screen b6_03:
    drag:
        add "b6_03"
screen b6_04:
    drag:
        add "b6_04"  
        
screen b7_01:
    drag:
        add "b7_01"
screen b7_02:
    drag:
        add "b7_02"
screen b7_03:
    drag:
        add "b7_03"
screen b7_04:
    drag:
        add "b7_04"

screen b8_01:
    drag:
        add "b8_01"
screen b8_02:
    drag:
        add "b8_02"
screen b8_03:
    drag:
        add "b8_03"
screen b8_04:
    drag:
        add "b8_04"

screen b9_01:
    drag:
        add "b9_01"
screen b9_02:
    drag:
        add "b9_02"
screen b9_03:
    drag:
        add "b9_03"
screen b9_04:
    drag:
        add "b9_04"  
        
screen b10_01:
    drag:
        add "b10_01"
screen b10_02:
    drag:
        add "b10_02"
screen b10_03:
    drag:
        add "b10_03"
screen b10_04:
    drag:
        add "b10_04"

screen b11_01:
    drag:
        add "b11_01"
screen b11_02:
    drag:
        add "b11_02"
screen b11_03:
    drag:
        add "b11_03"
screen b11_04:
    drag:
        add "b11_04"

screen b12_01:
    drag:
        add "b12_01"
screen b12_02:
    drag:
        add "b12_02"
screen b12_03:
    drag:
        add "b12_03"
screen b12_04:
    drag:
        add "b12_04"  

screen twobytwo_01:
    drag:
        add "two_01"
screen twobytwo_02:
    drag:
        add "two_02"
screen twobytwo_03:
    drag:
        add "two_03"
screen twobytwo_04:
    drag:
        add "two_04"  
        
screen threebythree_01:
    drag:
        add "three_01"
screen threebythree_02:
    drag:
        add "three_02"
screen threebythree_03:
    drag:
        add "three_03"
screen threebythree_04:
    drag:
        add "three_04"  
        
screen two_ver:
    drag:
        add "two_ver"
screen two_hor:
    drag:
        add "two_hor"
screen three_ver:
    drag:
        add "three_ver"
screen three_hor:
    drag:
        add "three_hor"
screen four_ver:
    drag:
        add "four_ver"
screen four_hor:
    drag:
        add "four_hor"
        
screen one:
    drag:
        add "one"
screen cross:
    drag:
        add "cross"

    
screen block1_choose:
    
    imagemap:
        auto "block1_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b1_01"), Hide("block1_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b1_02"), Hide("block1_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b1_03"), Hide("block1_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b1_04"), Hide("block1_choose") ]

screen block2_choose:
    
    imagemap:
        auto "block2_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b2_01"), Hide("block2_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b2_02"), Hide("block2_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b2_03"), Hide("block2_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b2_04"), Hide("block2_choose") ]

screen block3_choose:
    
    imagemap:
        auto "block3_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b3_01"), Hide("block3_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b3_02"), Hide("block3_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b3_03"), Hide("block3_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b3_04"), Hide("block3_choose") ]

screen block4_choose:
    
    imagemap:
        auto "block4_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b4_01"), Hide("block4_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b4_02"), Hide("block4_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b4_03"), Hide("block4_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b4_04"), Hide("block4_choose") ]
        
screen block5_choose:
    
    imagemap:
        auto "block5_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b5_01"), Hide("block5_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b5_02"), Hide("block5_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b5_03"), Hide("block5_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b5_04"), Hide("block5_choose") ]

screen block6_choose:
    
    imagemap:
        auto "block6_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b6_01"), Hide("block6_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b6_02"), Hide("block6_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b6_03"), Hide("block6_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b6_04"), Hide("block6_choose") ]
        
screen block7_choose:
    
    imagemap:
        auto "block7_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b7_01"), Hide("block7_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b7_02"), Hide("block7_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b7_03"), Hide("block7_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b7_04"), Hide("block7_choose") ]

screen block8_choose:
    
    imagemap:
        auto "block8_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b8_01"), Hide("block8_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b8_02"), Hide("block8_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b8_03"), Hide("block8_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b8_04"), Hide("block8_choose") ]
        
screen block9_choose:
    
    imagemap:
        auto "block9_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b9_01"), Hide("block9_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b9_02"), Hide("block9_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b9_03"), Hide("block9_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b9_04"), Hide("block9_choose") ]

screen block10_choose:
    
    imagemap:
        auto "block10_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b10_01"), Hide("block10_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b10_02"), Hide("block10_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b10_03"), Hide("block10_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b10_04"), Hide("block10_choose") ]
        
screen block11_choose:
    
    imagemap:
        auto "block11_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b11_01"), Hide("block11_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b11_02"), Hide("block11_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b11_03"), Hide("block11_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b11_04"), Hide("block11_choose") ]

screen block12_choose:
    
    imagemap:
        auto "block12_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("b12_01"), Hide("block12_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("b12_02"), Hide("block12_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("b12_03"), Hide("block12_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("b12_04"), Hide("block12_choose") ]
        
screen twobytwo_choose:
    
    imagemap:
        auto "twobytwo_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("twobytwo_01"), Hide("twobytwo_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("twobytwo_02"), Hide("twobytwo_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("twobytwo_03"), Hide("twobytwo_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("twobytwo_04"), Hide("twobytwo_choose") ]

screen threebythree_choose:
    
    imagemap:
        auto "threebythree_choose_%s.png"
        hotspot (269, 251, 372, 352) action [ Show("threebythree_01"), Hide("threebythree_choose") ] 
        hotspot (659, 231, 378, 376) action [ Show("threebythree_02"), Hide("threebythree_choose") ]
        hotspot (267, 634, 366, 369) action [ Show("threebythree_03"), Hide("threebythree_choose") ]
        hotspot (677, 641, 364, 359) action [ Show("threebythree_04"), Hide("threebythree_choose") ]
        
screen two_choose:
    
    imagemap:
        auto "two_choose_%s.png"
        hotspot (292, 248, 732, 349) action [ Show("two_hor"), Hide("two_choose") ] 
        hotspot (299, 640, 731, 367) action [ Show("two_ver"), Hide("two_choose") ]


screen three_choose:
    
    imagemap:
        auto "three_choose_%s.png"
        hotspot (292, 248, 732, 349) action [ Show("three_hor"), Hide("three_choose") ] 
        hotspot (299, 640, 731, 367) action [ Show("three_ver"), Hide("three_choose") ]
        
screen four_choose:
    
    imagemap:
        auto "four_choose_%s.png"
        hotspot (292, 248, 732, 349) action [ Show("four_hor"), Hide("four_choose") ] 
        hotspot (299, 640, 731, 367) action [ Show("four_ver"), Hide("four_choose") ]
        


I didn't changed option.rpy.
And only main menu screen is changed in screen.rpy.

I'm awaiting for your help...

Thanks.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Question on Screen Call.

#2 Post by PyTom »

MEGO. (My Eyes Glaze Over.)

My gut feeling is you probably don't want to do it like this, with so many images. Instead, you probably want to come up with a python data structure that represents blocks, rotations, and positions, and then use a screen with a for statement in it to show the blocks.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Question on Screen Call.

#3 Post by philat »

Yeah, I had the same reaction as PyTom and didn't respond at first, but I'm also procrastinating on work, so I figured what the heck! Here's a super simple (and probably not very elegant) structure I just drew up as an example. You'll have to refine and expand it considerably.

I also don't have much of an idea how you'd make the puzzle "solvable" -- it seems like to have 1 solution, you'd have to more or less predefine which blocks the player will have, and to have dynamic solutions would be... not impossible, but pretty difficult. Snapping into place and such are also more advanced mechanics that you'd have to figure out (although there's a useful jigsaw puzzle code you can find by searching the forum that might help).

Anyway, good luck with the rest of your game.

Code: Select all

init python:
    blocks_on_screen = [] ## list we'll iterate through to populate the draggables
    addedblock = None ## this is the part that is probably the most inelegant, but I didn't want to go through more iteration in the choosing block screen, so you can refine this mechanism

    class Block(): ## the Block class takes two parameters, the image path, and the degrees to rotate (90 will rotate the image 90 degrees clockwise). Degrees is 0 by default. Obvs expand as needed.
        def __init__(self, image, degrees=0):
            self.image = image
            self.degrees = degrees

    def add_block():
        if addedblock == "corner_upright":
            blocks_on_screen.append(Block("img/blockimage.png")) ## this is an example of Block being initialized -- and then added to the blocks_on_screen list
        elif addedblock == "corner_upsidedown":
            blocks_on_screen.append(Block("img/blockimage.png", 180))

init:
    transform rotate_blocks(degrees):
        rotate degrees

screen draggable_blocks():
    for block in blocks_on_screen:
        drag:
            add block.image at rotate_blocks(block.degrees) ## iterates through blocks_on_screen and adds a draggable image of each object's image (at defined path) at the transform

screen choose_block():
    vbox:
        textbutton "Choose corner block upright" action [SetVariable("addedblock", "corner_upright"), add_block] ## sets a variable to run the function add_block
        textbutton "Choose corner block upside down" action [SetVariable("addedblock", "corner_upsidedown"), add_block]

    use draggable_blocks ## shows the draggables on the same screen for now, but you can change this as needed

label start:

    show screen choose_block

    e "You've created a new Ren'Py game."



Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

Re: Question on Screen Call.

#4 Post by Love&Peace »

PyTom wrote:MEGO. (My Eyes Glaze Over.)

My gut feeling is you probably don't want to do it like this, with so many images. Instead, you probably want to come up with a python data structure that represents blocks, rotations, and positions, and then use a screen with a for statement in it to show the blocks.
Dear PyTom.

I had to make it show data, not images...
Thanks for your advice! I'll try it! :D

Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

Re: Question on Screen Call.

#5 Post by Love&Peace »

philat wrote:Yeah, I had the same reaction as PyTom and didn't respond at first, but I'm also procrastinating on work, so I figured what the heck! Here's a super simple (and probably not very elegant) structure I just drew up as an example. You'll have to refine and expand it considerably.

I also don't have much of an idea how you'd make the puzzle "solvable" -- it seems like to have 1 solution, you'd have to more or less predefine which blocks the player will have, and to have dynamic solutions would be... not impossible, but pretty difficult. Snapping into place and such are also more advanced mechanics that you'd have to figure out (although there's a useful jigsaw puzzle code you can find by searching the forum that might help).

Anyway, good luck with the rest of your game.

Code: Select all

init python:
    blocks_on_screen = [] ## list we'll iterate through to populate the draggables
    addedblock = None ## this is the part that is probably the most inelegant, but I didn't want to go through more iteration in the choosing block screen, so you can refine this mechanism

    class Block(): ## the Block class takes two parameters, the image path, and the degrees to rotate (90 will rotate the image 90 degrees clockwise). Degrees is 0 by default. Obvs expand as needed.
        def __init__(self, image, degrees=0):
            self.image = image
            self.degrees = degrees

    def add_block():
        if addedblock == "corner_upright":
            blocks_on_screen.append(Block("img/blockimage.png")) ## this is an example of Block being initialized -- and then added to the blocks_on_screen list
        elif addedblock == "corner_upsidedown":
            blocks_on_screen.append(Block("img/blockimage.png", 180))

init:
    transform rotate_blocks(degrees):
        rotate degrees

screen draggable_blocks():
    for block in blocks_on_screen:
        drag:
            add block.image at rotate_blocks(block.degrees) ## iterates through blocks_on_screen and adds a draggable image of each object's image (at defined path) at the transform

screen choose_block():
    vbox:
        textbutton "Choose corner block upright" action [SetVariable("addedblock", "corner_upright"), add_block] ## sets a variable to run the function add_block
        textbutton "Choose corner block upside down" action [SetVariable("addedblock", "corner_upsidedown"), add_block]

    use draggable_blocks ## shows the draggables on the same screen for now, but you can change this as needed

label start:

    show screen choose_block

    e "You've created a new Ren'Py game."



Dear philat
Thanks for your help! And for sample code!
I'll try hard. Many thanks!! :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Sugar_and_rice