[SOLVED] input field to save game (works but 2 problems)

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
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

[SOLVED] input field to save game (works but 2 problems)

#1 Post by Pierrou »

Hi again :oops: (Sorry for my poor english :( )

I'm trying to improve my save menu. Actually, when you choose a slot, it saves your game with 50 characters of the dialogs in game.

I'm trying to put an input field that provide you to choose the name of your save. (by default, it'll be 50 characters of the dialogs in game)

This is my save menu without any input (works fine but weird code i know :P )

Code: Select all

init python:
    config.thumbnail_width = 100
    config.thumbnail_height = 75

screen save():
    tag menu
    key "s" action Return()
    default mouse_clicked = False

    if int(persistent._file_page) == 1:
        add "image/ui/saveload/s_back30.png"
        fixed at KeymapTransform([('mousedown_1', SetScreenVariable('mouse_clicked', True)), ('mouseup_1', SetScreenVariable('mouse_clicked', False))]):
            imagebutton idle "image/ui/saveload/nextbutton_idle.png" hover("image/ui/saveload/nextbutton_clicked.png" if mouse_clicked else "image/ui/saveload/nextbutton_hover.png") xpos 738 ypos 535 focus_mask None action FilePage(2)
    else:
        add "image/ui/saveload/s_back60.png"
        fixed at KeymapTransform([('mousedown_1', SetScreenVariable('mouse_clicked', True)), ('mouseup_1', SetScreenVariable('mouse_clicked', False))]):
            imagebutton idle "image/ui/saveload/backbutton_idle.png" hover("image/ui/saveload/backbutton_clicked.png" if mouse_clicked else "image/ui/saveload/backbutton_hover.png") xpos 738 ypos 535 focus_mask None action FilePage(1)

    imagebutton auto "image/ui/saveload/exit_%s.png" xpos 620 ypos 520 focus_mask None action Return()

    default tt = Tooltip((Null(), "", "", "", Null()))
    $ borderblack = "image/ui/saveload/borderblack.png"

    hbox:
        xysize (600, 550)
        pos (30, 30)
        spacing 0
        box_wrap True

        if int(persistent._file_page) == 1:
            $ page_sl1 = 1
            $ page_sl2 = 31
        else:
            $ page_sl1 = 31
            $ page_sl2 = 61

        for i in range(page_sl1, page_sl2):
            # Each file slot is a button.
            $ file_name = FileSlotName(i, 30)
            $ file_time = FileTime(i, format='%d/%m/%Y %H:%M')
            $ slot_foot = str(i)
            if len(slot_foot) < 3:
                $ slot_foot = '0' + slot_foot
            if len(slot_foot) < 3:
                $ slot_foot = '0' + slot_foot
            $ slot_foot = "No." + slot_foot
            $ save_name = FileSaveName(i)


            vbox:
                spacing 0

                button:
                    left_padding 2
                    right_padding 2
                    top_padding 2
                    bottom_padding 2
                    left_margin 0
                    right_margin 0
                    top_margin 0
                    bottom_margin 0
                    xysize (104, 79)
                    background None
                    hover_background "image/ui/saveload/borderred.png"
                    action [SetVariable("save_name",_last_say_what[:50]), FileAction(i)]
                    hovered tt.Action((FileScreenshot(i), slot_foot, file_time, save_name, borderblack))

                    xfill True

                    add FileScreenshot(i)

                    key "save_delete" action FileDelete(i)
                    key "K_BACKSPACE" action FileDelete(i)

                null height 11 width 106
       
    add tt.value[0] xpos 625 ypos 155
    add tt.value[4] xpos 625 ypos 155
    
    vbox:
        xsize 150
        pos (600, 175)

        text tt.value[1] ypos 80 size 15
        text tt.value[2] ypos 80 size 15
        text tt.value[3] xpos 5 ypos 83 size 12

For the input i just add this before :

Code: Select all

screen modal_input:
    modal True
    window style "input_window":
        has vbox

        text prompt style "input_prompt"
        input id "input" style "input_text" default default

init -2 python:
    class get_save_name(FileSave):
        def __init__(self, name, confirm=False, newest=True, page=None, cycle=False):
            super(get_save_name,self).__init__(name=name,confirm=confirm,newest=newest,page=page,cycle=cycle)
        def __call__(self):
            renpy.call_in_new_context("get_save_name")
            return super(get_save_name,self).__call__()

label get_save_name:
    show screen save
    $ save_nameinput = renpy.call_screen("modal_input", prompt="Enter save name", default=save_nameinput, length=20)
    $ renpy.retain_after_load()
    return
and in my save screen, i changed :

Code: Select all

action [SetVariable("save_name",_last_say_what[:50]), FileAction(i)]
into this :

Code: Select all

action [get_save_name(i), FileAction(i)]

It works, but there's some bug...

1) It shows the Yes/No prompt with "Are you sure you want to overwrite this save ?" anytime i pick a slot... And it doesn't care if i hit the "Yes" or the "No" button :lol:. So, how to disable this prompt just in that case you picked an empty slot ?

2) As i said, i'm trying to put the dialogs in game by default. But i can't call $ save_name = FileSaveName(i) for default=save_nameinput cause it's not in the same screen...

It's just 2 little problems but i can't solve them... :oops: Thank you so much in advance !
Last edited by Pierrou on Sun Jan 25, 2015 1:27 am, edited 1 time in total.
Sorry for my english, it's not my native language. :s

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#2 Post by Pierrou »

I bump it :)

I've tried to disable the yes/no for "Are you sure you want to overwrite this save ?" but i need it if the player overwrite a save :/
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: input field to save game (works but 2 problems)

#3 Post by shivanshs9 »

Can you share your project, please? It's getting quite hard to imagine an error in this case and I also don't have any resources to test my theories about why the confirmation screen is coming up for every slot... So, maybe just a project with the minimal required files will be sufficient to test out the problem here...
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#4 Post by Pierrou »

For the dummy project, do you need all the script files ?

Or just the save screen and yes/no screen ?
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: input field to save game (works but 2 problems)

#5 Post by shivanshs9 »

Just the screens and the used images, so that no error pops up... And, don't forget about the get_save_name function too... Basically, a project that includes the problematic screen which can work with the included resources.
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#6 Post by Pierrou »

This is the link ;)

https://www.dropbox.com/sh/1hwh4nsc5y5y ... NI_Ua?dl=0

Tell me if you can't open it.
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: input field to save game (works but 2 problems)

#7 Post by shivanshs9 »

Sorry for the late reply... :( Kinda busy...
Okay, I solved your first problem and it's truly a very petty one... Basically, Ren'Py saves the game when you call the get_save_name() class and you still used FileAction after that... :lol:
So, your code as it should be:

Code: Select all

button:
    left_padding 2
    right_padding 2
    top_padding 2
    bottom_padding 2
    left_margin 0
    right_margin 0
    top_margin 0
    bottom_margin 0
    xysize (104, 79)
    background None
    hover_background "image/ui/saveload/borderred.png"
    #action [SetVariable("save_name",_last_say_what[:50]), FileAction(i)]
    action get_save_name(i) # Removed FileAction!
    hovered tt.Action((FileScreenshot(i), slot_foot, file_time, save_name, borderblack))
And, change get_save_name() from confirm=False to confirm=True:

Code: Select all

init -2 python:
    class get_save_name(FileSave):
        def __init__(self, name, confirm=True, newest=True, page=None, cycle=False):
            super(get_save_name,self).__init__(name=name,confirm=confirm,newest=newest,page=page,cycle=cycle)
        def __call__(self):
            renpy.call_in_new_context("get_save_name")
            return super(get_save_name,self).__call__() #<-This already saves your game!
And, that solves your first problem!

:?: Also, can you please elaborate your second problem since it's difficult to understand... :?
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#8 Post by Pierrou »

Thank you so much :D

It works fine :)


For my second problem (i'm sorry if my english is bad, but i'm french :s) i would like to fill the input field by the save_name.

Code: Select all

label get_save_name:
    show screen save
    $ save_nameinput = renpy.call_screen("modal_input", prompt="Enter save name", default=save_name, length=20) #<= the save_name is from screen save()... That's why i can't call this variable :/
    $ renpy.retain_after_load()
    return

When you pick a save slot :

=> Input field open
=> Input field automatically filled by "FileSaveName()"

Do you understand better now ? :oops:
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: input field to save game (works but 2 problems)

#9 Post by shivanshs9 »

No problem! Actually, english isn't my first language too... :oops:
Now, as for the now-understandable problem...............
DONE!!!! :smile:
Actually, you already did half of the work...

Code: Select all

button:
    #styles, etcetera...
    action [SetVariable("save_name",_last_say_what[:50]), get_save_name(i)] # <- Saves the last 50 lines to the save_name variable!
So, as you can see I re-inserted your line: action SetVariable("save_name",_last_say_what[:50]) before get_save_name(i)! Also, due to

Code: Select all

$ save_name = renpy.call_screen("modal_input", prompt="Enter save name", default=save_name, length=20)
save_name will already be used as a default input text!
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#10 Post by Pierrou »

Yeah ! It works ! Tanks a lot :P

Is it possible to delete those {w} in the name ? ^^

Image
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: input field to save game (works but 2 problems)

#11 Post by shivanshs9 »

Shoot down your new problem for it is solved! :smile:
Well, actually, parsing and removing text tags was quite difficult... But, I got an idea on how to do it from the readback history script...

Code: Select all

init -2 python:
    disallowed_tags = ["size", "w", "b", "a", "i"] # <- Increase this list
    # remove text tags from dialogue lines 
    disallowed_tags_regexp = ""
    for tag in disallowed_tags:
        if disallowed_tags_regexp != "":
            disallowed_tags_regexp += "|"
        disallowed_tags_regexp += "{"+tag+"=.*?}|{"+tag+"}|{/"+tag+"}"

    import re
    remove_tags_expr = re.compile(disallowed_tags_regexp) # remove tags undesirable in readback
    def preparse_say_for_store(input):
        global remove_tags_expr
        if input:
            return re.sub(remove_tags_expr, "", input)

    class get_save_name(FileSave):
        def __init__(self, name, confirm=True, newest=True, page=None, cycle=False):
            super(get_save_name,self).__init__(name=name,confirm=confirm,newest=newest,page=page,cycle=cycle)
        def __call__(self):
            global save_name
            save_name=preparse_say_for_store(store._last_say_what) # Passes the _last_say_what to the function to remove unwanted text tags!
            renpy.call_in_new_context("get_save_name")
            return super(get_save_name,self).__call__()
Just change the disallowed_tags array to remove more number of tags...
Also, for your screen:

Code: Select all

button:
    # Extra stufff
    action get_save_name(i)
Currently, I haven't tested the code with all the text tags, so if you encounter any problem with a particular text tag, don't be afraid to ask!
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
Pierrou
Regular
Posts: 53
Joined: Fri Dec 05, 2014 8:25 pm
Projects: Togainu no Chi, DMMD, Omerta, ...
Skype: pierrouney
Location: France
Contact:

Re: input field to save game (works but 2 problems)

#12 Post by Pierrou »

EDIT : It works fine ! I work with another person and DropBox didn't upload the file :p

Thank you so much for your help ! :P
Sorry for my english, it's not my native language. :s

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: [SOLVED] input field to save game (works but 2 problems)

#13 Post by shivanshs9 »

Glad to be of help!
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

Post Reply

Who is online

Users browsing this forum: Google [Bot]