[RESOLVED] Adding in-game variables to the file save name and Json?

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
tincrumbs
Newbie
Posts: 13
Joined: Mon Jul 09, 2018 11:05 pm
Projects: Buy Gones
Contact:

[RESOLVED] Adding in-game variables to the file save name and Json?

#1 Post by tincrumbs »

Hey! Me again... I have a feeling I'm gonna be here a lot now that I've finally signed up for an account. cx

1) I simply don't understand how to add in-game variables to the default naming of save files. By default, it uses the FileTime(name, format=u'%b %d, %H:%M', empty=u'', page=None) to take the time the file was saved and you can use the same function to add other text, right? Like, I have a new one that says FileTime(slot, format=_"words.", empty=_"") and that shows up fine. However, I want to add the route chosen and the entered player name when the player saves. When I use something like FileTime(slot, format=_"[name]") it says "Maximum recursion depth reached". For some context: I'm kind of new to coding (just finishing up my very first coding class on Javascript and HTML) and pretty unfamiliar with Python. Also, I'm setting up my save screen like this because I rather like the way I save otome games on my PSVita.

2) Can you customize text separately from each other on this screen? For example, let's say I want the time and date to be a different size and color than the size and color of the chapter name and I want the character name to be different from those size and colors. Can I do that within the FileTime() function, or would I need to make different styles for each different kind of text I want? So would style slot_button_time, style slot_button_chapter, and style slot_button_character would all need to be separate or not?

3) Also, as a side note, I just want to make sure I'm understanding these other functions correctly: FileSlotName() only keeps track of the number of slots, correct? Ex. I have 100 slots, so I use this function to count from 1 to 100 in the top right corner of all my slots. And FileSaveName() only goes in and keeps track of the name the slot was saved under. Is that right?

Here's the code I've been working on if it's needed and a screenshot for reference:

Code: Select all

screen save():
    tag menu
    use file_slots(_("Save"))

screen load():
    tag menu
    use file_slots(_("Load"))

screen file_slots(title):
    default page_name_value = FilePageNameInputValue(pattern=_("Saves"), auto=_("Automatic saves"), quick=_("Quick saves"))
    use game_menu(title, scroll="viewport"):
        fixed:
        	order_reverse True        	
        	grid gui.file_slot_cols gui.file_slot_rows:
                	style_prefix "slot"
               		xalign 0.01
                	yalign 0.36
                	spacing gui.slot_spacing
                	for i in range(gui.file_slot_cols * gui.file_slot_rows):
                   		$ slot = i + 1
                    		button:
                        		action FileAction(slot)
                        		has hbox
                        		add FileScreenshot(slot) xpos 93
                        		text ( " %d. " % slot
                            			+ FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M \n"), empty=_("Empty Slot."))
                            			+ FileTime(slot, format=_("Words."), empty=_(""))
                            			+ FileSaveName(slot)) style "slot_name_text" align (0.01, 0.0)                           
                        		key "save_delete" action FileDelete(slot)
                        
style page_label is gui_label
style page_label_text is gui_label_text
style page_button is gui_button
style page_button_text is gui_button_text

style slot_button is gui_button
style slot_button_text is gui_button_text
style slot_time_text is slot_button_text
style slot_name_text is slot_button_text

style page_label:
    xpadding 50
    ypadding 3

style page_label_text:
    text_align 0.5
    layout "subtitle"
    hover_color gui.hover_color

style page_button:
    properties gui.button_properties("page_button")

style page_button_text:
    properties gui.button_text_properties("page_button")

style slot_button:
    properties gui.button_properties("slot_button")

style slot_button_text:
    color ("#800000")
    size 14
    first_indent 95
    newline_indent True
One final note: I struggle often to understand the documentation and do better with examples, so if there's an applicable part of the documentation that I'm just missing, I'd be very grateful if you also added on an example for my sake besides just linking. Sorry if I'm missing a thread here, too! Google wasn't turning up anything and my search doesn't really work on this site. Thank y'all for your time!
Last edited by tincrumbs on Mon Jul 23, 2018 2:25 pm, edited 3 times in total.

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

Re: Adding in-game variables to the file save name?

#2 Post by gas »

1) You can use save_name at any point in your script.
$ save_name="Chapter"+str(chaptnum)
...for example.
For a better management, you can use a json callback.
Example

Code: Select all

init python:
    def myjson(jsondata):
        jsondata["name"]=charaname
config.save_json_callback.append(myjson)
That register the value of charaname variable each time you save.
To retrieve and show the value you have to use FileJson function inside the slot screen.
Example

Code: Select all

$ daname=FileJson(i,key="name")
text "[daname ]"
#### I CAN'T VERIFY THE CODE RIGHT NOW. So prone to syntax errors, but the logic is correc6
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

User avatar
tincrumbs
Newbie
Posts: 13
Joined: Mon Jul 09, 2018 11:05 pm
Projects: Buy Gones
Contact:

Re: Adding in-game variables to the file save name?

#3 Post by tincrumbs »

Thank you!! You're a lifesaver, gas! I wish the documentation was more clear about Json. I keep getting so lost. I got to trying to implement it into the slot screen, but was still stuck there... u.u It took me forever to even understand that Json was a completely different language...

Now I've got a few new problems and questions, though, if you wouldn't mind helping me out some more:

1) Which parts can and cannot be named the exact same thing? Is this how you would set it up? I keep getting pickling errors and I'm pretty sure cause I'm defining variables multiple times by accident.

Code: Select all

def match1(d): #I have the "jsondata" bit in parenthesis as "d" in my code following other examples. Is that correct? Is one preferable? What does it even do?
        d["match2"]=match3
config.save_json_callback.append(match1)
# --- slot screen
$ match4=FileJson(i,key="match2")
text "[match4 ]"
2) Can two separate variables in the python be combined into one under the "def" (umm... pretty sure that's not what you call it, but idk what else to call it cx)? I want to make one def (def characterName) using the two variables firstname and lastname. Can I even do that? Do I want to match up things differently than in the code block I did above?

Me and $ save_name weren't getting along very well for a second. I accidentally deleted it's bit in the code! But I've got it back in there now and if I can just get the characterName to work, my screen will look almost exactly like I want it to!! I can't thank you enough for your help! <3

User avatar
tincrumbs
Newbie
Posts: 13
Joined: Mon Jul 09, 2018 11:05 pm
Projects: Buy Gones
Contact:

Re: [UNRESOLVED] Adding in-game variables to the file save name + Json?

#4 Post by tincrumbs »

I just separated the variables into two and it's working great, but I'm still curious about my last two questions!! ❤️

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: [UNRESOLVED] Adding in-game variables to the file save name and Json?

#5 Post by Saltome »

1. When you define labels, screens, transforms, "defs" you need to use a unique identifier.
You could technically use the same name to define different variables, but they are still different.
2. Yes, like this.

Code: Select all

init python:
    def concatonate_name(forename, surname):
        return forename + " " + surname
label start:
    $ save_name = concatonate_name("John", "Green")
    "end"
    return
3. You should go to youtube and watch some basic python programming videos to understand some basic programming concepts.
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

User avatar
tincrumbs
Newbie
Posts: 13
Joined: Mon Jul 09, 2018 11:05 pm
Projects: Buy Gones
Contact:

Re: [UNRESOLVED] Adding in-game variables to the file save name and Json?

#6 Post by tincrumbs »

'Thank you for your help!! c:

Post Reply

Who is online

Users browsing this forum: Google [Bot], piinkpuddiin