Call via phone in-game

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
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Call via phone in-game

#1 Post by MoonByte »

So I want to have the feature where the player can at certain points call a number of their choice.
I COULD go the easy way and just have them click on a name in a dropdown list, but I kind of want them to actually type the numbers in (like in old-school point&click games).
Now I have looked around and believe I might be able to do that via the "Numbers Minigame" from Alex, but if so, then I am not 100% sure how to change the code to recognize multiple different outcomes?

I mean, let's say the numbers to call are 667-4982, 442-9554 and 388-1108.
I would need the game to not only realize that one of those numbers was dialed and send the player to the right person, I would also need it to realize when a unknown number is dialed. If I see it correctly, Alex's code seems to only have a right and a wrong result (and I don't even fully understand how the game concludes that the right one was put in).
I really would appreciate, if someone could either help me through this code to understand and change it or - if there is maybe a simpler variation (no idea, maybe with imagebuttons and variables or something), to offer me some revelation in that direction.

Code from Alex's Number Minigame

Code: Select all

transform roto_transform (roto_var):
    # ATL transform that will rotate our displayables to "roto_var" degrees
    rotate roto_var
    rotate_pad False

##### The game screen
screen numbers_scr:
   
    # It is better to operate this game with mouse only, so just disable cursor and enter keys
    key "K_LEFT" action Hide("nonexistent_screen")
    key "K_RIGHT" action Hide("nonexistent_screen")
    key "K_UP" action Hide("nonexistent_screen")
    key "K_DOWN" action Hide("nonexistent_screen")
    key "K_RETURN" action Hide("nonexistent_screen")
    key "K_KP_ENTER" action Hide("nonexistent_screen")
   
    ##### Timer
    #
    # It returns "smth" every second and "win" (if all buttons were clicked) or "lose" (if time was up)
    timer 1 action [Return("smth"), If( game_timer>1, If( numbers_buttons[-1]["b_to_show"] == False, Return("win"), SetVariable("game_timer", game_timer-1) ), Return("lose") ) ] repeat True
    text "[game_timer]" size 25 xpos 10 ypos 10

   
    for each_b in sorted(numbers_buttons, reverse=True):
        if each_b["b_to_show"]:
            $ text_var = each_b["b_value"]
            $ i = each_b["b_number"] - 1
            button:
               
                # Will show image if "b_value" was set as file name or displayable.
                #background None
                #add each_b["b_value"]
                # Also it is neccessary to comment out the next  4 lines.
               
                #background "image.png"          # Sets button's appearance
                text '[text_var]{size=18}.{/size}' size 30 align (0.5, 0.55) color "#000"
                xminimum 100 xmaximum 100
                yminimum 100 ymaximum 100
                xpos each_b["b_x_pos"]
                ypos each_b["b_y_pos"]
                anchor (0.5, 0.5)
                action If (i == -1, SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                    If (numbers_buttons[i]["b_to_show"] == False,
                        SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                        SetVariable("game_timer", game_timer-1) )  )          # Wrong click reduces the time left by 1 second
                at roto_transform (renpy.random.randint (0, 10)*36)
               
   
    # It might be usefull to show the order of buttons to click if it's not obvious.
    side "c b":
        area (150, 05, 640, 70)         # The size of hint's area
       
        viewport id "vp":
            draggable True
           
            hbox:
                xalign 1.0
               
                # The same buttons declaration, but they will be scaled down
                for each_b in numbers_buttons:
                    $ text_var = each_b["b_value"]
                    button:
                                       
                        # Will show image if "b_value" was set as file name or displayable.
                        #background None
                        #add each_b["b_value"]
                        # Also it is neccessary to comment out the next  4 lines.
               
                        #background "image.png"          # Sets button's appearance
                        text '[text_var]{size=18}.{/size}' size 30 align (0.5, 0.55) color "#000"
                        xminimum 100 xmaximum 100
                        yminimum 100 ymaximum 100
                        action If (each_b["b_to_show"], Hide("nonexistent_screen"), None)
                        at Transform(zoom=0.5)           # Size
       
        bar value XScrollValue("vp")
      

label numbers_game:
   
    #####
    #
    # At first, let's set the values for buttons
    $ numbers_buttons = []
    $ buttons_values = []
   
    # This might be numbers,
    python:
        for i in range (1, renpy.random.randint (10, 15) ):
            buttons_values.append (str(i) )
   
    # or letters,
    #$ buttons_values = [u"а", u"б", u"в", u"г", u"д", u"е", u"ё", u"ж", u"з", u"и", u"й", u"к", u"л", u"м", u"н", u"о", u"п", u"р", u"с", u"т", u"у", u"ф", u"х", u"ц", u"ч", u"ш", u"щ", u"ъ", u"ы", u"ь", u"э", u"ю", u"я" ]

    # or images,
    #$ buttons_values = ["img1", "img2", "my_img.png"]

    # This will make the description for all buttons (numbers, values and positions)
    python:
        for i in range (0, len(buttons_values) ):
            numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (10, 70))*10, "b_y_pos":(renpy.random.randint (15, 50))*10, "b_to_show":True} )
   
    "To win the game - click all the buttons one after another (start from \"1\")."
   
    # Before start the game, let's set the timer
    $ game_timer = 20
   
    # Shows the game screen
    show screen numbers_scr
   
    # The loop will exist untill game screen returns win or lose
    label loop:
        $ result = ui.interact()
        $ game_timer = game_timer
        if result == "smth":
            jump loop

    if result == "lose":
        hide screen numbers_scr
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        "You lose! Try again."
        jump numbers_game
       
    if result == "win":
        hide screen numbers_scr
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        "You win!"
        return

    return

User avatar
Lucky1443
Regular
Posts: 128
Joined: Tue Jul 07, 2015 11:59 am
Projects: SACRIFICE
Tumblr: Lucky1443
Deviantart: Lucky1443
Contact:

Re: Call via phone in-game

#2 Post by Lucky1443 »

Maybe you could try to use this if you still need help? viewtopic.php?f=8&t=40764
OPEN for SPRITE/CG ART viewtopic.php?f=62&t=38654 FREE TO USE ASSETS viewtopic.php?f=52&t=39634

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Call via phone in-game

#3 Post by MoonByte »

Ah, that is a actual interesting/fitting idea!
Thanks, I will look into that :D

Post Reply

Who is online

Users browsing this forum: tim640