[SOLVED] Trying to make a passcode/ lock

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
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] Trying to make a passcode/ lock

#1 Post by Kinmoku »

Hi all,

I have a diary with a 3 digit pin code on it. If the player guesses the correct answer (306) they can unlock the diary.

The problem I'm having is when I push "down" on the second and third number, it doesn't show the image for "9", but if I push up it does. Also, if I choose 9 on the first number, the 9s on the second and third will appear. After messing around for a while, every time 9 appears on the first number "999" appears on all. What's going on? Here's my code (sorry it's super long for such an easy thing! I think my problem is that there must be a simpler way of doing this but I don't know how):

Definitions in script.rpy:

Code: Select all

    default firstlock = 10.0 # I am starting with 10 to avoid entering negative numbers
    default secondlock = 10.0
    default thirdlock = 10.0

Code: Select all

label diary_explore:
    call screen diary_unlock
    
    $ result = _return
    
    if result == "first_up": # push up on first dial
        $ firstlock += 1.0
    elif result == "first_down": # push down on first dial
        $ firstlock -= 1.0
    elif result == "second_up": # push up on second dial
        $ secondlock += 1.0
    elif result == "second_down": # push down on second dial
        $ secondlock -= 1.0
    elif result == "third_up": # push up on third dial
        $ thirdlock += 1.0
    elif result == "third_down": # push down on third dial
        $ thirdlock -= 1.0
        
    elif result == "enter": # try entering combination
        if firstlock == 13.0: # there are two "3s" (13.0 and 3.0). same for 0 and 6
            if secondlock == 10.0:
                if thirdlock == 16.0:
                    m "Unlocked!" # etc
                elif thirdlock == 6.0:
                    m "Unlocked!" # etc
                else:
                    m "Nope."
                    jump diary_explore
                    
            elif secondlock == 0.0:
                if thirdlock == 16.0:
                    m "Unlocked!" # etc
                elif thirdlock == 6.0:
                    m "Unlocked!" # etc
                else:
                    m "Nope."
                    jump diary_explore
                        
            else:
                m "Nope."
                jump katiediary_explore
                        
        elif firstlock == 3.0:
            if secondlock == 10.0:
                if thirdlock == 16.0:
                    m "Unlocked!" # etc

                elif thirdlock == 6.0:
                    m "Unlocked!" # etc

                else:
                    m "Nope."
                    jump diary_explore
                    
            elif secondlock == 0.0:
                if thirdlock == 16.0:
                    m "Unlocked!" # etc

                elif thirdlock == 6.0:
                    m "Unlocked!" # etc

                else:
                    m "Nope."
                    jump diary_explore
                        
            else:
                m "Nope."
                jump diary_explore
                    
        else:
            m "Nope."
            jump diary_explore
            
    if firstlock == 10.0: # dial images
        show lock_1 0
    elif firstlock == 11.0:
        show lock_1 1
    elif firstlock == 12.0:
        show lock_1 2
    elif firstlock == 13.0:
        show lock_1 3
    elif firstlock == 14.0:
        show lock_1 4
    elif firstlock == 15.0:
        show lock_1 5
    elif firstlock == 16.0:
        show lock_1 6
    elif firstlock == 17.0:
        show lock_1 7
    elif firstlock == 18.0:
        show lock_1 8
    elif firstlock == 19.0:
        show lock_1 9
    elif firstlock == 9.0:
        show lock_1 9
    elif firstlock == 8.0:
        show lock_1 8
    elif firstlock == 7.0:
        show lock_1 7
    elif firstlock == 6.0:
        show lock_1 6
    elif firstlock == 5.0:
        show lock_1 5
    elif firstlock == 4.0:
        show lock_1 4
    elif firstlock == 3.0:
        show lock_1 3
    elif firstlock == 2.0:
        show lock_1 2
    elif firstlock == 1.0:
        show lock_1 1
    elif firstlock == 0.0:
        show lock_1 0
        $ firstlock += 10.0 # to ensure it doesn't go in negative
    elif firstlock == 20.0:
        show lock_1 0
        $ firstlock -= 10.0 # to ensure it doesn't go into twenties and beyond
    if secondlock == 10.0:
        show lock_2 0
    elif secondlock == 11.0:
        show lock_2 1
    elif secondlock == 12.0:
        show lock_2 2
    elif secondlock == 13.0:
        show lock_2 3
    elif secondlock == 14.0:
        show lock_2 4
    elif secondlock == 15.0:
        show lock_2 5
    elif secondlock == 16.0:
        show lock_2 6
    elif secondlock == 17.0:
        show lock_2 7
    elif secondlock == 18.0:
        show lock_2 8
    elif secondlock == 19.0:
        show lock_2 9
    elif firstlock == 9.0:
        show lock_2 9
    elif secondlock == 8.0:
        show lock_2 8
    elif secondlock == 7.0:
        show lock_2 7
    elif secondlock == 6.0:
        show lock_2 6
    elif secondlock == 5.0:
        show lock_2 5
    elif secondlock == 4.0:
        show lock_2 4
    elif secondlock == 3.0:
        show lock_2 3
    elif secondlock == 2.0:
        show lock_2 2
    elif secondlock == 1.0:
        show lock_2 1
    elif secondlock == 20.0:
        show lock_2 0
        $ secondlock -= 10.0
    elif secondlock == 0.0:
        show lock_2 0
        $ secondlock += 10.0
    if thirdlock == 10.0:
        show lock_3 0
    elif thirdlock == 11.0:
        show lock_3 1
    elif thirdlock == 12.0:
        show lock_3 2
    elif thirdlock == 13.0:
        show lock_3 3
    elif thirdlock == 14.0:
        show lock_3 4
    elif thirdlock == 15.0:
        show lock_3 5
    elif thirdlock == 16.0:
        show lock_3 6
    elif thirdlock == 17.0:
        show lock_3 7
    elif thirdlock == 18.0:
        show lock_3 8
    elif thirdlock == 19.0:
        show lock_3 9
    elif firstlock == 9.0:
        show lock_3 9
    elif thirdlock == 8.0:
        show lock_3 8
    elif thirdlock == 7.0:
        show lock_3 7
    elif thirdlock == 6.0:
        show lock_3 6
    elif thirdlock == 5.0:
        show lock_3 5
    elif thirdlock == 4.0:
        show lock_3 4
    elif thirdlock == 3.0:
        show lock_3 3
    elif thirdlock == 2.0:
        show lock_3 2
    elif thirdlock == 1.0:
        show lock_3 1
    elif thirdlock == 20.0:
        show lock_3 0
        $ thirdlock -= 10.0
    elif thirdlock == 0.0:
        show lock_3 0
        $ thirdlock += 10.0
            
    jump diary_explore
My screen is fairly straight-forward:

Code: Select all

screen diary_unlock:
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('first_up') xpos 1411 ypos 479 focus_mask None
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('second_up') xpos 1452 ypos 476 focus_mask None
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('third_up') xpos 1493 ypos 473 focus_mask None
    
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('first_down') xpos 1416 ypos 554 focus_mask None
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('second_down') xpos 1457 ypos 551 focus_mask None
    imagebutton idle Solid("#0000", xysize=(35, 26)) clicked Return('third_down') xpos 1498 ypos 548 focus_mask None
        
    imagebutton idle Solid("#0000", xysize=(42, 54)) clicked Return('enter') xpos 1357 ypos 503 focus_mask None

And my image definitions are here. I wonder if the issue could also be because they're the same image files all at once?

Code: Select all

image lock_1 0:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_0.png"
    
image lock_1 1:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_1.png"
    
image lock_1 2:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_2.png"
    
image lock_1 3:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_3.png"
    
image lock_1 4:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_4.png"
    
image lock_1 5:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_5.png"
    
image lock_1 6:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_6.png"
    
image lock_1 7:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_7.png"
    
image lock_1 8:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_8.png"
    
image lock_1 9:
    xanchor 0 xpos 1418
    yanchor 0 ypos 512
    
    "images/present/lock_9.png"
    
image lock_2 0:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_0.png"
    
image lock_2 1:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_1.png"
    
image lock_2 2:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_2.png"
    
image lock_2 3:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_3.png"
    
image lock_2 4:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_4.png"
    
image lock_2 5:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_5.png"
    
image lock_2 6:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_6.png"
    
image lock_2 7:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_7.png"
    
image lock_2 8:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_8.png"
    
image lock_2 9:
    xanchor 0 xpos 1460
    yanchor 0 ypos 510
    
    "images/present/lock_9.png"
    
image lock_3 0:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_0.png"
    
image lock_3 1:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_1.png"
    
image lock_3 2:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_2.png"
    
image lock_3 3:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_3.png"
    
image lock_3 4:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_4.png"
    
image lock_3 5:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_5.png"
    
image lock_3 6:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_6.png"
    
image lock_3 7:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_7.png"
    
image lock_3 8:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_8.png"
    
image lock_3 9:
    xanchor 0 xpos 1502
    yanchor 0 ypos 508
    
    "images/present/lock_9.png"
I've attached an image to help visualise the problem.
diary.jpg
Last edited by Kinmoku on Tue Mar 12, 2019 10:37 am, edited 1 time in total.

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

Re: Trying to make a passcode/ lock

#2 Post by philat »

That's uh, really long. There are lots of ways to do this -- the following is relatively simple. (Haven't run this, there may be typos, etc., but the basic concept works.)

Code: Select all

default diary_passcode1 = 0
default diary_passcode2 = 0
default diary_passcode3 = 0

screen diary_unlock():
    # groups buttons to make it easier to read
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable("diary_passcode1", 0 if diary_passcode1==9 else diary_passcode1+1) xpos 1411 ypos 479 focus_mask None # a if cond else b is a really simple way to work around looping structures like digits
    add "images/present/lock_[diary_passcode1].png" # use dynamic image to show the right image. I didn't bother with positioning but you can add that easily
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('diary_passcode1', 9 if diary_passcode1==0 else diary_passcode1-1) xpos 1416 ypos 554 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('diary_passcode2', 0 if diary_passcode2==9 else diary_passcode2+1) xpos 1452 ypos 476 focus_mask None
    add "images/present/lock_[diary_passcode2].png"
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('diary_passcode2', 9 if diary_passcode2==0 else diary_passcode2-1) xpos 1457 ypos 551 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('diary_passcode3', 0 if diary_passcode3==9 else diary_passcode3+1) xpos 1493 ypos 473 focus_mask None
    add "images/present/lock_[diary_passcode3].png"
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('diary_passcode3', 9 if diary_passcode3==0 else diary_passcode3-1) xpos 1498 ypos 548 focus_mask None

    imagebutton idle Solid("#0000", xysize=(42, 54)) action Return() xpos 1357 ypos 503 focus_mask None

label diary:
    call screen diary_unlock # since the up/down buttons use SetVariable it only returns on pushing the "enter" button
    if [diary_passcode1, diary_passcode2, diary_passcode3] == [3, 0, 6]:
        "unlock"
    else:
        "wrong code"
        jump diary

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Trying to make a passcode/ lock

#3 Post by Kinmoku »

philat wrote: Sat Mar 09, 2019 1:33 pm That's uh, really long. There are lots of ways to do this -- the following is relatively simple. (Haven't run this, there may be typos, etc., but the basic concept works.)
Thanks Philat, this is so much smaller and simpler :) I didn't know about variable images. Unfortunately, the buttons are not showing the images though. When I hit enter, it works (says the passcode is right/wrong) and then shows the numbers afterwards... but hitting the buttons doesn't change the image so there's no indication to the player what number they're on.

Here's the rest of my code:

Code: Select all

    default firstlock = 0
    default secondlock = 0
    default thirdlock = 0

Code: Select all

label diary_explore:
    
    call screen diary_unlock
    
    if [firstlock, secondlock, thirdlock] == [3, 0, 6]:
        mil "That's it."
                    
        jump diary_open
        
    else:
        $ randomnum = renpy.random.randint(1, 3)

        if randomnum==1:
            tm "Nope."
            
        elif randomnum==2:
            tm "That's not it."
            
        elif randomnum==3:
            tm "No luck."
            
        jump diary_explore

Code: Select all

screen diary_unlock:
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable("firstlock", 0 if firstlock==9 else firstlock+1) xpos 1411 ypos 479 focus_mask None
    add "images/present/lock_[firstlock].png" xpos 1418 ypos 512
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('firstlock', 9 if firstlock==0 else firstlock-1) xpos 1416 ypos 554 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('secondlock', 0 if secondlock==9 else secondlock+1) xpos 1452 ypos 476 focus_mask None
    add "images/present/lock_[secondlock].png" xpos 1460 ypos 510
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('secondlock', 9 if secondlock==0 else secondlock-1) xpos 1457 ypos 551 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('thirdlock', 0 if thirdlock==9 else thirdlock+1) xpos 1493 ypos 473 focus_mask None
    add "images/present/lock_[thirdlock].png" xpos 1502 ypos 508
    imagebutton idle Solid("#0000", xysize=(35, 26)) action SetVariable('thirdlock', 9 if thirdlock==0 else thirdlock-1) xpos 1498 ypos 548 focus_mask None

    imagebutton idle Solid("#0000", xysize=(42, 54)) action Return() xpos 1357 ypos 503 focus_mask None

    

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

Re: Trying to make a passcode/ lock

#4 Post by philat »

Well, it should work. Don't know what you're doing to make it not.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Trying to make a passcode/ lock

#5 Post by Remix »

You probably want a restart_interaction to get the screen to refresh. (also note: you could just modulo the values rather than if else)

action [ SetVariable('thirdlock', (thirdlock + 1) % 10 ), renpy.restart_interaction() ]

*might* be Function( renpy.restart_interaction ) ... I always forget which functions are Action safe or not
Frameworks & Scriptlets:

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

Re: Trying to make a passcode/ lock

#6 Post by philat »

It works without restart_interaction. Again, unclear what's happening.


User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Trying to make a passcode/ lock

#8 Post by Kinmoku »

I'm using Renpy 7.1.3.1092

It's not working with the code I showed above.

I tried "[ SetVariable('thirdlock', (thirdlock + 1) % 10 ), renpy.restart_interaction() ]" but this caused the game to freeze every time the screen appeared. I read the documentation (https://www.renpy.org/doc/html/other.html) and it sounds like it should word within an action.

I'm stuck :(

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Trying to make a passcode/ lock

#9 Post by Kinmoku »

Andredron wrote: Sun Mar 10, 2019 9:57 am viewtopic.php?f=51&t=51868
This is it :D It works! The only issue I am having now is when I push down first, I get this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While loading <'Image' u'images/present/lock_9.0.png'>:
  File "game/script.rpy", line 5335, in script call
    call table_explore
  File "game/explore.rpy", line 1896, in script call
    call katiediary_explore
  File "game/explore.rpy", line 2115, in script
    call screen diary_unlock
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
IOError: Couldn't find file 'images/present/lock_9.0.png'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 5335, in script call
    call table_explore
  File "game/explore.rpy", line 1896, in script call
    call katiediary_explore
  File "game/explore.rpy", line 2115, in script
    call screen diary_unlock
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1861, in execute
    self.call("execute")
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1849, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/statements.py", line 203, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/exports.py", line 2755, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "/Applications/renpy-6.99.11-sdk/renpy/ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 2672, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 3158, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 2075, in draw_screen
    renpy.config.screen_height,
  File "render.pyx", line 487, in renpy.display.render.render_screen
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/screen.py", line 669, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "accelerator.pyx", line 110, in renpy.display.accelerator.transform_render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 580, in render
    return cache.get(self, render=True)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 266, in get
    surf = image.load()
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 625, in load
    surf = renpy.display.pgrender.load_image(renpy.loader.load(self.filename), self.filename)
  File "/Applications/renpy-6.99.11-sdk/renpy/loader.py", line 576, in load
    raise IOError("Couldn't find file '%s'." % name)
IOError: Couldn't find file 'images/present/lock_9.0.png'.

Darwin-17.7.0-x86_64-i386-64bit
Ren'Py 7.1.3.1092
My Friend Katie 1.0
Sun Mar 10 15:38:17 2019
If I push up first, it works. If I go through all the numbers, then push down, it doesn't crash.
My images are called "lock_1.png, lock_2.png" etc. I shouldn't need to add "lock_9.0.png, lock 8.0.png" etc should I? I have not used decimals anywhere for this.

Here is my code:

Code: Select all

screen diary_unlock:
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(firstlock < 9, SetVariable("firstlock", firstlock + 1), SetVariable("firstlock", 0)) xpos 1411 ypos 479 focus_mask None
    add "images/present/lock_%s.png"%(firstlock) xpos 1418 ypos 512
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(firstlock > 0, SetVariable("firstlock", firstlock - 1), SetVariable("firstlock", 9)) xpos 1416 ypos 554 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(secondlock < 9, SetVariable("secondlock", secondlock + 1), SetVariable("secondlock", 0)) xpos 1452 ypos 476 focus_mask None
    add "images/present/lock_%s.png"%(secondlock) xpos 1460 ypos 510
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(secondlock > 0, SetVariable("secondlock", secondlock - 1), SetVariable("secondlock", 9)) xpos 1457 ypos 551 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(thirdlock < 9, SetVariable("thirdlock", thirdlock + 1), SetVariable("thirdlock", 0))  xpos 1493 ypos 473 focus_mask None
    add "images/present/lock_%s.png"%(thirdlock) xpos 1502 ypos 508
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(thirdlock > 0, SetVariable("thirdlock", thirdlock - 1), SetVariable("thirdlock", 9)) xpos 1498 ypos 548 focus_mask None

    imagebutton idle Solid("#0000", xysize=(42, 54)) action Return() xpos 1357 ypos 503 focus_mask None

User avatar
Andredron
Miko-Class Veteran
Posts: 718
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Trying to make a passcode/ lock

#10 Post by Andredron »

lock_9.0


lock_90 delit .

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Trying to make a passcode/ lock

#11 Post by Kinmoku »

Andredron wrote: Sun Mar 10, 2019 1:15 pm lock_9.0


lock_90 delit .
Sorry. I do not understand. I have attached an image with my file names, but I get this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While loading <'Image' u'images/present/lock_10.0.png'>:
  File "game/script.rpy", line 5335, in script call
    call table_explore
  File "game/explore.rpy", line 1896, in script call
    call katiediary_explore
  File "game/explore.rpy", line 2115, in script
    call screen diary_unlock
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
IOError: Couldn't find file 'images/present/lock_10.0.png'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 5335, in script call
    call table_explore
  File "game/explore.rpy", line 1896, in script call
    call katiediary_explore
  File "game/explore.rpy", line 2115, in script
    call screen diary_unlock
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1861, in execute
    self.call("execute")
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1849, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/statements.py", line 203, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/exports.py", line 2755, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "/Applications/renpy-6.99.11-sdk/renpy/ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 2672, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 3158, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 2075, in draw_screen
    renpy.config.screen_height,
  File "render.pyx", line 487, in renpy.display.render.render_screen
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/screen.py", line 669, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 147, in renpy.display.render.render
  File "render.pyx", line 235, in renpy.display.render.render
  File "accelerator.pyx", line 110, in renpy.display.accelerator.transform_render
  File "render.pyx", line 235, in renpy.display.render.render
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 580, in render
    return cache.get(self, render=True)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 266, in get
    surf = image.load()
  File "/Applications/renpy-6.99.11-sdk/renpy/display/im.py", line 625, in load
    surf = renpy.display.pgrender.load_image(renpy.loader.load(self.filename), self.filename)
  File "/Applications/renpy-6.99.11-sdk/renpy/loader.py", line 576, in load
    raise IOError("Couldn't find file '%s'." % name)
IOError: Couldn't find file 'images/present/lock_10.0.png'.

Darwin-17.7.0-x86_64-i386-64bit
Ren'Py 7.1.3.1092
My Friend Katie 1.0
Tue Mar 12 11:20:21 2019
Screen Shot 2019-03-12 at 11.21.22.png
Screen Shot 2019-03-12 at 11.21.22.png (25.33 KiB) Viewed 835 times
I tried changing all to decimals (lock_1.0.png etc) but this didn't work either.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Trying to make a passcode/ lock

#12 Post by Kinmoku »

Never-mind. I have simply added decimals to everything and now it works.

For anyone who wants to see the final code, here it is:

In script.rpy:

Code: Select all

    default firstlock = 0.0
    default secondlock = 0.0
    default thirdlock = 0.0
In screens.rpy:

Code: Select all

screen diary_unlock:
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(firstlock < 9, SetVariable("firstlock", firstlock + 1.0), SetVariable("firstlock", 0.0)) xpos 1411 ypos 479 focus_mask None
    add "images/present/lock_%s.png"%(firstlock) xpos 1418 ypos 512
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(firstlock > 0, SetVariable("firstlock", firstlock - 1.0), SetVariable("firstlock", 9.0)) xpos 1416 ypos 554 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(secondlock < 9, SetVariable("secondlock", secondlock + 1.0), SetVariable("secondlock", 0.0)) xpos 1452 ypos 476 focus_mask None
    add "images/present/lock_%s.png"%(secondlock) xpos 1460 ypos 510
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(secondlock > 0, SetVariable("secondlock", secondlock - 1.0), SetVariable("secondlock", 9.0)) xpos 1457 ypos 551 focus_mask None

    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(thirdlock < 9, SetVariable("thirdlock", thirdlock + 1.0), SetVariable("thirdlock", 0.0))  xpos 1493 ypos 473 focus_mask None
    add "images/present/lock_%s.png"%(thirdlock) xpos 1502 ypos 508
    imagebutton idle Solid("#0000", xysize=(35, 26)) action If(thirdlock > 0, SetVariable("thirdlock", thirdlock - 1.0), SetVariable("thirdlock", 9.0)) xpos 1498 ypos 548 focus_mask None

    imagebutton idle Solid("#0000", xysize=(42, 54)) action Return() xpos 1357 ypos 503 focus_mask None
Back in script.rpy:

Code: Select all

label diary_explore:
    call screen diary_unlock
    
    if [firstlock, secondlock, thirdlock] == [3.0, 0.0, 6.0]:
        tm "That's it!"
                    
        jump diary_open
        
    else:
        $ randomnum = renpy.random.randint(1, 3)

        if randomnum==1:
            tm "Nope."
            
        elif randomnum==2:
            tm "That's not it."
            
        elif randomnum==3:
            tm "No luck."
            
        jump diary_explore
Images in folder are called "lock_0.0.png, lock_1.0.png etc"

I used "lock_10.0.png" as well (for 0).

Post Reply

Who is online

Users browsing this forum: Google [Bot]