JSON problem[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.
Post Reply
Message
Author
User avatar
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

JSON problem[SOLVED!]

#1 Post by Yuuji »

Hello! I'm trying to implement some save features in my game, but I have one problem. Here's some code:

Code: Select all

for i in range(1, 5):
        if FileLoadable(i):
            imagebutton:
                auto "image/menu/sl/panel_filled_%s.png"
                xpos 43
                ypos 61 + (i - 1) * 111
                action NullAction()
            add FileScreenshot(i) xpos 74 ypos 76 + (i - 1) * 111
            $ phrase = FileJson(i, "phrase", empty = " ---empty--- ", missing = " ---missing--- ")
            $ file_name = FileSlotName(i, 8)
            $ file_time = FileTime(i)
            $ save_name = FileSaveName(i)
            $ scene_name = FileJson(i, "scenename", empty = " ---empty--- ", missing = " ---missing--- ")
            
            text "[file_name]. [file_time!t]\n[save_name!t]\n[phrase]\n[scene_name]" xpos 240 ypos 76 + (i - 1) * 111 color "#000000" size 16
        else:
            imagebutton:
                auto "image/menu/sl/panel_empty_%s.png"
                xpos 43
                ypos 61 + (i - 1) * 111
                action FileSave(i)
This code is used in save screen to display save panels.
Now, the code that used for JSON:

Code: Select all

init python:

    def save_phrase(d):
        last_phrase = current_line[1]
        d["phrase"] = last_phrase
        save_scene_name = sceneName
        d["scenename"] = save_scene_name

    config.save_json_callbacks = [save_phrase]
And code in scenario file that assigns sceneName variable value:

Code: Select all

label start:
    $sceneName = "Начало"
    "Яркий солнечный свет на дороге словно объявляет о приходе лета."
Now, about my problem. Last phrase works well. It is always saved successfully and loaded successfully too. But instead of scene name '---missing---' is displayed. I suppose that "scenename" just don't save and I don't know why. Maybe you have some ideas? Thanks in advance.
Last edited by Yuuji on Sat Mar 07, 2015 5:56 am, edited 1 time in total.
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: JSON problem

#2 Post by PyTom »

You want to do:

Code: Select all

    config.save_json_callbacks.append(save_phrase)
There's a default json callback that saves the scene name.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

Re: JSON problem

#3 Post by Yuuji »

PyTom wrote:You want to do:

Code: Select all

    config.save_json_callbacks.append(save_phrase)
PyTom, thank you for your answer! But your code works as well as mine. I'm trying to save a last phrase from the game and scene name, but only last phrase is saved.
PyTom wrote:There's a default json callback that saves the scene name.
I'm sorry but I can't find it :(
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

User avatar
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

Re: JSON problem

#4 Post by Yuuji »

Now I've got one more problem. When I do this:

Code: Select all

    config.save_json_callbacks = []
nothing changed. save_phrase function is in callbacks list doesn't dissapear from there. I tried to delete save files, to comment

Code: Select all

    #d["phrase"] = last_phrase
in save_phrase function but last_phrase is saved and I can do nothing with it. I don't know what to do :(
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

User avatar
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

Re: JSON problem

#5 Post by Yuuji »

Oh... My problem is solved. I just made a stupid mistake. Now all works fine.
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], voluorem