Secret typing

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
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Secret typing

#1 Post by isobellesophia »

Hello

I know about renpy.input but how would i make such a secret code that when the player types a word like..

"I love you" without showing the input, but instead, you can type anytime like revealing a secret event. Like typing i love you, that'll jump into the other label like dating scene and whatsoever.

Just like when you press 's', it will screenshot the game, but i would like a typing a word.


Sry bad english and thank you.
I am a friendly user, please respect and have a good day.


Image

Image


rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Secret typing

#2 Post by rayminator »

you can try this

Code: Select all

KEYS = []
    CODE = ["H","e","l","l","o","T","h","e","r","e"]

Code: Select all

init:
    transform bottom_to_top:
        yalign 1.0
        linear 5.0 yalign 0.2

screen keynav:
    key "K_UP" action Call("konami", k = "up")
    key "K_DOWN" action Call("konami", k = "down")
    key "K_LEFT" action Call("konami", k = "left")
    key "K_RIGHT" action Call("konami", k = "right")
    key "K_b" action Call("konami", k = "b")
    key "K_a" action Call("konami", k = "a")

label konami(k):

    if len(KEYS) < len(CODE) and CODE[len(KEYS)] == k:
        $ KEYS.append(k)
    else:
        $ KEYS = []
    if KEYS == CODE:
        call successful_code from _call_successful_code
        $ KEYS = []
    return

label successful_code:
    if not CHEAT:
        $ CHEAT = True
    else:
        $ CHEAT = False
    return

label cheats:

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Secret typing

#3 Post by Alex »

isobellesophia wrote: Sat Sep 28, 2019 9:09 am ...
Check this entry - https://www.renpy.org/wiki/renpy/doc/co ... onami_Code

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Secret typing

#4 Post by isobellesophia »

Hello, late reply but thanks for this.

Also, it is possible to make two sets or three of codes? Like a different one.

Thanks.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Secret typing

#5 Post by Alex »

isobellesophia wrote: Sun Oct 13, 2019 10:51 pm Hello, late reply but thanks for this.

Also, it is possible to make two sets or three of codes? Like a different one.

Thanks.
You could try it like

Code: Select all

init python hide:

    class KonamiListener(renpy.Displayable):

        def __init__(self):

            renpy.Displayable.__init__(self)

            import pygame

            # This is the index (in code sequence) of the key we're
            # expecting.
            self.state = 0
            
            self.codes_match_list = []
            self.first_click = True

            # The codes themselves.
            self.codes = [
                {"ind":0, "code":[pygame.K_UP, pygame.K_UP], "target_label":"secret_0"},
                {"ind":1, "code":[pygame.K_UP, pygame.K_DOWN, pygame.K_DOWN], "target_label":"secret_1"},
                {"ind":2, "code":[pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT], "target_label":"secret_2"},
            ]

        # This function listens for events.
        def event(self, ev, x, y, st):
            import pygame

            # We only care about keydown events.
            if ev.type != pygame.KEYDOWN:
                return

            else:
                match_flag = False
                for code in self.codes: # check each sequence in codes
                    if (self.state < len(code["code"])) and ev.key == code["code"][self.state]:
                        if code["ind"] in self.codes_match_list:
                            match_flag = True
                        elif code["ind"] not in self.codes_match_list and self.first_click:
                            self.codes_match_list.append(code["ind"]) # add sequence index in a list
                            match_flag = True
                        
                    else: # remove sequence index if key not match
                        if code["ind"] in self.codes_match_list:
                            self.codes_match_list.remove(code["ind"])
                        
                # If it's not the key we want, go back to the start of the state
                # machine.
                if not match_flag:
                    self.state = 0
                    self.codes_match_list = []
                    self.first_click = True
                    return

                # Otherwise, go to the next state.
                self.state += 1
                self.first_click = False

                # If we are at the end of the code, then call the target label in
                # the new context. (After we reset the state machine.)
                for i in self.codes_match_list:
                    if self.state == len(self.codes[i]["code"]):
                        res = self.codes[self.codes_match_list[0]]["target_label"]
                        self.state = 0
                        self.codes_match_list = []
                        self.first_click = True
                        renpy.call_in_new_context(res)

                return

        # Return a small empty render, so we get events.
        def render(self, width, height, st, at):
            return renpy.Render(1, 1)


    # Create a KonamiListener to actually listen for the code.
    store.konami_listener = KonamiListener()

    # This adds konami_listener to each interaction.
    def konami_overlay():
        ui.add(store.konami_listener)

    config.overlay_functions.append(konami_overlay)


# This is called in a new context when the konami code is entered.
label secret_0:
    "UP - UP"
    return
    
label secret_1:
    "UP - DOWN - DOWN"
    return

label secret_2:
    "UP - DOWN - LEFT"
    return

# The game starts here.

label start:
    "..."

Post Reply

Who is online

Users browsing this forum: No registered users