[SOLVED] Phone pin number unlock puzzle

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] Phone pin number unlock puzzle

#1 Post by Kinmoku »

Hi all,

I am trying to add a phone pin number unlock puzzle to my game. I plan on using it in a couple of places: with a phone and with a safe. Both images have a key pad and enter/ reset button, and will be unlocked with 4 digits. I looked at this thread about number password unlocks viewtopic.php?t=1625 but I can't figure out how to use renpy.input without the keyboard, and just using imagebuttons. I also need to ensure the numbers are in a specific order so the pin only unlocks with the correct combination.

Another way of thinking about this was using AddToSet, which I've never used before. I thought I'd try it out but sadly it crashes.

My code:

Code: Select all


screen safeunlock_search:
    imagebutton idle Solid("#0000", xysize=(51, 42)) action AddToSet("safenumber", "1") xpos 752 ypos 460 focus_mask None
    imagebutton idle Solid("#0000", xysize=(51, 44)) action AddToSet("safenumber", "4") xpos 752 ypos 505 focus_mask None
    imagebutton idle Solid("#0000", xysize=(51, 46)) action AddToSet("safenumber", "7") xpos 752 ypos 552 focus_mask None

#etc for all numbers    
    
    imagebutton idle Solid("#0000", xysize=(51, 46)) clicked Return('enter') xpos 752 ypos 601 focus_mask None

Code: Select all

label cupboardsafe_explore:
    
    #$ safenumber = renpy.input("What is the code?", "1504", length=4) ## pls ignore this attempt
    
    call screen safeunlock_search
    
    $ result = _return
    
    if result == "enter":
        if "safenumber" == [1.0, 5.0, 0.0, 4.0]:
            mil "Got it!"
            
        else:
            mil "That didn't work."
The error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 9516, in script call
    call corneropen_explore
  File "game/explore.rpy", line 2244, in script
    call screen safeunlock_search
  File "renpy/common/000statements.rpy", line 531, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "renpy/common/00action_data.rpy", line 417, in __call__
    self.set.add(self.value)
AttributeError: 'unicode' object has no attribute 'add'

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

Full traceback:
  File "game/script.rpy", line 9516, in script call
    call corneropen_explore
  File "game/explore.rpy", line 2244, in script
    call screen safeunlock_search
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1949, in execute
    self.call("execute")
  File "/Applications/renpy-6.99.11-sdk/renpy/ast.py", line 1937, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/statements.py", line 277, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 531, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/exports.py", line 2905, 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 297, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/core.py", line 2702, 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 3518, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/screen.py", line 714, in event
    rv = self.child.event(ev, x, y, st)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/behavior.py", line 962, in event
    return handle_click(self.clicked)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/behavior.py", line 897, in handle_click
    rv = run(action)
  File "/Applications/renpy-6.99.11-sdk/renpy/display/behavior.py", line 320, in run
    return action(*args, **kwargs)
  File "renpy/common/00action_data.rpy", line 417, in __call__
    self.set.add(self.value)
AttributeError: 'unicode' object has no attribute 'add'
Any ideas?
Last edited by Kinmoku on Tue Mar 31, 2020 12:10 pm, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Phone pin number unlock puzzle

#2 Post by gas »

The error is using quotes in the action AddToSet("safenumber", "1"), while it should be AddToSet(safenumber, "1").
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

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

Re: Phone pin number unlock puzzle

#3 Post by philat »

In my experience AddToSet is finicky and I tend to avoid it. There are a lot of ways you can do this so there isn't really any one right thing to do. But this should be a reference point you can use. viewtopic.php?p=465629#p465629

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: Phone pin number unlock puzzle

#4 Post by Kinmoku »

gas wrote: Tue Mar 31, 2020 9:34 am The error is using quotes in the action AddToSet("safenumber", "1"), while it should be AddToSet(safenumber, "1").
Ah damn. I tried it the other way around but didn't think to do it this way. Anyway, it works now :) I had to change the return code a little so it registered the correct input (I also added a reset) but here's my final code if it helps anyone:

Code: Select all

init python:
    safenumber = []
    
    ###

label cupboardsafe_explore:
    
    call screen safeunlock_search
    
    $ result = _return
    
    if result == "enter":
        if safenumber == ["1", "5", "0", "4"]:
            mil "Got it."
     
            jump cornersafeopen_explore
            
        else:
            $ safenumber = [] ## it resets on fail
            
In screens:

Code: Select all

screen safeunlock_search:
    imagebutton idle Solid("#0000", xysize=(51, 42)) action AddToSet(safenumber, "1") xpos 752 ypos 460 focus_mask None
    imagebutton idle Solid("#0000", xysize=(51, 44)) action AddToSet(safenumber, "4") xpos 752 ypos 505 focus_mask None
    imagebutton idle Solid("#0000", xysize=(51, 46)) action AddToSet(safenumber, "7") xpos 752 ypos 552 focus_mask None
    imagebutton idle Solid("#0000", xysize=(51, 46)) clicked Return('reset') xpos 752 ypos 601 focus_mask None

    imagebutton idle Solid("#0000", xysize=(54, 42)) clicked AddToSet(safenumber, "2") xpos 808 ypos 460 focus_mask None
    imagebutton idle Solid("#0000", xysize=(54, 44)) clicked AddToSet(safenumber, "5") xpos 808 ypos 505 focus_mask None
    imagebutton idle Solid("#0000", xysize=(54, 46)) clicked AddToSet(safenumber, "8") xpos 808 ypos 552 focus_mask None
    imagebutton idle Solid("#0000", xysize=(54, 46)) clicked AddToSet(safenumber, "0") xpos 808 ypos 601 focus_mask None

    imagebutton idle Solid("#0000", xysize=(52, 42)) clicked AddToSet(safenumber, "3") xpos 867 ypos 460 focus_mask None
    imagebutton idle Solid("#0000", xysize=(52, 44)) clicked AddToSet(safenumber, "6") xpos 867 ypos 505 focus_mask None
    imagebutton idle Solid("#0000", xysize=(52, 46)) clicked AddToSet(safenumber, "9") xpos 867 ypos 552 focus_mask None
    imagebutton idle Solid("#0000", xysize=(52, 46)) clicked Return('enter') xpos 867 ypos 601 focus_mask None

Post Reply

Who is online

Users browsing this forum: Wildmask