Implementing a functional keypad [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.
Message
Author
User avatar
shortycake
Regular
Posts: 119
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland, Behind the Doll's eyes[WIP]
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Implementing a functional keypad [SOLVED]

#16 Post by shortycake »

I tested the code but there is an error when I tried to display the code.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 237, in script
  File "game/script.rpy", line 237, in python
TypeError: sequence item 0: expected string, int found

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

Full traceback:
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\execution.py", line 294, in run
    node.execute()
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\ast.py", line 732, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\python.py", line 1382, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 237, in <module>
    $ our_code_string = ", ".join(our_code)
TypeError: sequence item 0: expected string, int found

Windows-XP-5.1.2600-SP3
Ren'Py 6.17.4.409
trial 0.0

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Implementing a functional keypad [SOLVED]

#17 Post by xela »

shortycake wrote:I tested the code but there is an error when I tried to display the code.
My bad, I didn't test any of it either, try:

Code: Select all

$ our_code_string = ", ".join(str(i) for i in our_code)
Like what we're doing? Support us at:
Image

User avatar
shortycake
Regular
Posts: 119
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland, Behind the Doll's eyes[WIP]
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Implementing a functional keypad [SOLVED]

#18 Post by shortycake »

xela wrote:My bad, I didn't test any of it either, try:

Code: Select all

$ our_code_string = ", ".join(str(i) for i in our_code)
waah! It works now! Thank you very much for the help! You're the best!

User avatar
shortycake
Regular
Posts: 119
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland, Behind the Doll's eyes[WIP]
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Implementing a functional keypad [SOLVED]

#19 Post by shortycake »

weep, oh, sorry for asking again xela but can you also teach us how not to include a counter in the keypad? thank you.. ; u ;

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#20 Post by ileikturtles »

It should be fairly easy to remove (assuming you only want 1 attempt here?)

Code: Select all

label start:
    
    $ keys = []
    show screen key_pad
    jump crack_the_code
    
label crack_the_code:
    python:
        while len(keys) < 4:
            $ result = ui.interact()
            if isinstance(result, int):
                $ keys.append(result)
    if keys == [2, 5, 1, 4]:
        hide screen key_pad
        jump success
    else:
        hide screen key_pad
        jump failure

return
Try that :)

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#21 Post by ileikturtles »

ileikturtles wrote:It should be fairly easy to remove (assuming you only want 1 attempt here?)

Code: Select all

label start:
    
    $ keys = []
    show screen key_pad
    jump crack_the_code
    
label crack_the_code:
    python:
        while len(keys) < 4:
            $ result = ui.interact()
            if isinstance(result, int):
                $ keys.append(result)
    if keys == [2, 5, 1, 4]:
        hide screen key_pad
        jump success
    else:
        hide screen key_pad
        jump failure

return
Try that :)
Argh this is the 1st version without the randomized code! So basically just use the old code with the "our_code" xela told us to swap in, remove any line with "$ counter" (there were 2) and change else to remove the If statement as shown above :)

User avatar
shortycake
Regular
Posts: 119
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland, Behind the Doll's eyes[WIP]
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Implementing a functional keypad [SOLVED]

#22 Post by shortycake »

ileikturtles: thank you very much! XD

pocari
Newbie
Posts: 7
Joined: Wed Aug 05, 2015 3:22 am
Contact:

Re: Implementing a functional keypad [SOLVED]

#23 Post by pocari »

Hello! Is there's a way to put cancel button and/or hint button on this code without messing up with the counter? Thank you very much!

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#24 Post by ileikturtles »

pocari wrote:Hello! Is there's a way to put cancel button and/or hint button on this code without messing up with the counter? Thank you very much!
It would be the same, but include more buttons on your imagemap (ie. a "BACK" or whatever for cancel, and another for hint).

Back is pretty self explanatory (close screen I guess, or a jump), but the hint functionality would depend on what exactly you want to show. I made a kind of "remember" function where if you get the number wrong, she's like "uhh, I think it was..." and then there's a 50/50 chance she remembers each number or says "something". It's a bit sloppy, I've seen her recall all four or none ("The code was... something, something... something, and then something.") but it works in a pinch! Here's my code:

Code: Select all

label codeAttempt2:
        scene bg office alarm
        
        s "Argh... try to remember, Scottie."
        
        $ hint1 = renpy.random.choice(["[keycode[0]]", "something"])
        $ hint2 = renpy.random.choice(["[keycode[1]]", "something"])
        $ hint3 = renpy.random.choice(["[keycode[2]]", "something"])
        $ hint4 = renpy.random.choice(["[keycode[3]]", "something"])

        s "The code was... "
        extend "%(hint1)s, "
        extend "%(hint2)s... "
        extend "%(hint3)s "
        extend "and then %(hint4)s."
        s "Okay, let's take another stab at this."
        
        scene bg Safe Alarmed
        
        $ keyInputs2 = []
        
        show screen SafeAlarm
        python:
            while len(keyInputs2) < len(keycode):
                result = ui.interact()
                if isinstance(result, int):
                    keyInputs2.append(result)
                    
        if keyInputs2 == keycode:
            hide screen SafeAlarm
            play voice "door open close.mp3"
            jump successAlarm
            
        else:
            hide screen SafeAlarm
            jump failAlarm

pocari
Newbie
Posts: 7
Joined: Wed Aug 05, 2015 3:22 am
Contact:

Re: Implementing a functional keypad [SOLVED]

#25 Post by pocari »

I tried putting cancel button using text button since image button doesn't work (I don't know how to make it work ehehe) and it works but the real problem is the counter. When I try to go back (since I have 2 more turns) I have no more turn left and it's game over. I think the solution for this problem is putting an 'enter button' which will confirm how many turns you make (some sort of flag) but I really have no idea how to code it.

For the hint, I was thinking about like where the player can find the code or something like that but your idea is good too!

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#26 Post by ileikturtles »

pocari wrote:I tried putting cancel button using text button since image button doesn't work (I don't know how to make it work ehehe) and it works but the real problem is the counter. When I try to go back (since I have 2 more turns) I have no more turn left and it's game over.
I think the solution for this problem is putting an 'enter button' which will confirm the how many turns you make (some sort of flag) but I really have no idea how to code it.

For the hint, I was thinking about like where the player can find the code or something like that but your idea is good too!
Oh, duh! I forgot about you asked about the counter too, my bad! I think an easy way to get around that is to put the $ counter +1 in the failure response thing (or the success one too, depending on what this counter has an effect on).

So the end bit would be like

Code: Select all

if keyInputs2 == keycode:
            hide screen SafeAlarm
            play voice "door open close.mp3"
            jump successAlarm
            
        else:
            hide screen SafeAlarm
            $ counter +=1
            jump failAlarm
Note that I took out the counter for my game, I just make it into two separate screens (called keyInputs and keyInputs2). I don't remember the exact problem but something wasn't working for me.

The full four sections of the code here (there are short narrative bits in between but I left them out):

Code: Select all

label codeAttempt1:
    
    $ keyInputs1 = []
    $ firstCode = True
    
    show screen SafeCombination
    python:
        while len(keyInputs1) < len(keycode):
            result = ui.interact()
            if isinstance(result, int):
                keyInputs1.append(result)
                
    if keyInputs1 == keycode:
        hide screen SafeCombination
        play voice "door open close.mp3"
        jump success
        
    else:
        hide screen SafeCombination
        play voice "red alarm 2.mp3"
        scene bg safeRedBulb 
        pause 1.5
        jump alarm

label success:
    scene bg safeGreenBulb
    s "Another job well done, old girl."
################################################ 

label codeAttempt2:
        scene bg office alarm
        
        s "Argh... try to remember, Scottie."
        
        $ hint1 = renpy.random.choice(["[keycode[0]]", "something"])
        $ hint2 = renpy.random.choice(["[keycode[1]]", "something"])
        $ hint3 = renpy.random.choice(["[keycode[2]]", "something"])
        $ hint4 = renpy.random.choice(["[keycode[3]]", "something"])

        s "The code was... "
        extend "%(hint1)s, "
        extend "%(hint2)s... "
        extend "%(hint3)s "
        extend "and then %(hint4)s."
        s "Okay, let's take another stab at this."
        
        scene bg Safe Alarmed
        
        $ keyInputs2 = []
        
        show screen SafeAlarm
        python:
            while len(keyInputs2) < len(keycode):
                result = ui.interact()
                if isinstance(result, int):
                    keyInputs2.append(result)
                    
        if keyInputs2 == keycode:
            hide screen SafeAlarm
            play voice "door open close.mp3"
            jump successAlarm
            
        else:
            hide screen SafeAlarm
            jump failAlarm
################################################ 

screen SafeCombination: 
    imagemap:
        ground "WORLD/Safe.png"
        hover "WORLD/SafeCombination Hover.png"

        hotspot (508, 458, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(1)] #--> 1
        hotspot (583, 460, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(2)] #--> 2
        hotspot (661, 462, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(3)] #--> 3        
        hotspot (508, 531, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(4)] #--> 4
        hotspot (583, 533, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(5)] #--> 5
        hotspot (661, 535, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(6)] #--> 6           
        hotspot (508, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(7)] #--> 7
        hotspot (583, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(8)] #--> 8        
        hotspot (661, 611, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(9)] #--> 9    
        
screen SafeAlarm: 
    imagemap:
        ground "WORLD/Safe Alarmed.png"
        hover "WORLD/SafeCombination Hover.png"
        
        hotspot (508, 458, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(1)] #--> 1
        hotspot (583, 460, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(2)] #--> 2
        hotspot (661, 462, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(3)] #--> 3        
        hotspot (508, 531, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(4)] #--> 4
        hotspot (583, 533, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(5)] #--> 5
        hotspot (661, 535, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(6)] #--> 6           
        hotspot (508, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(7)] #--> 7
        hotspot (583, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(8)] #--> 8        
        hotspot (661, 611, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(9)] #--> 9


pocari
Newbie
Posts: 7
Joined: Wed Aug 05, 2015 3:22 am
Contact:

Re: Implementing a functional keypad [SOLVED]

#27 Post by pocari »

I don't know if this works since my cancel button doesn't work... orz

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#28 Post by ileikturtles »

pocari wrote:I don't know if this works since my cancel button doesn't work... orz
Why isn't the cancel button working?

The action would be: action Jump("whereverCancelGoes")" < you put in the label name for where you would jump to if they cancel the safe cracking

So, implemented would be:

Code: Select all

screen SafeCombination: 
    imagemap:
        ground "WORLD/Safe.png"
        hover "WORLD/SafeCombination Hover.png"

        hotspot (your 4 coordinates) action Jump("whereverCancelGoes")
        hotspot (508, 458, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(1)] #--> 1
        hotspot (583, 460, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(2)] #--> 2
        hotspot (661, 462, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(3)] #--> 3        
        hotspot (508, 531, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(4)] #--> 4
        hotspot (583, 533, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(5)] #--> 5
        hotspot (661, 535, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(6)] #--> 6           
        hotspot (508, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(7)] #--> 7
        hotspot (583, 607, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(8)] #--> 8        
        hotspot (661, 611, 57, 56) action [Play ("sound", "buttonpress.ogg"), Return(9)] #--> 9
        
Try that :D

pocari
Newbie
Posts: 7
Joined: Wed Aug 05, 2015 3:22 am
Contact:

Re: Implementing a functional keypad [SOLVED]

#29 Post by pocari »

Oooooh! It works now! Thank you very much for your help!

User avatar
ileikturtles
Regular
Posts: 32
Joined: Sun Nov 23, 2014 7:54 pm
Projects: Adventures of Scottie
Organization: StudioFondue
Tumblr: ileikturtles
Contact:

Re: Implementing a functional keypad [SOLVED]

#30 Post by ileikturtles »

pocari wrote:Oooooh! It works now! Thank you very much for your help!
Nooooooooooo problem! Go forth, my child.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]