Problem with variables, please help! [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
tim640
Regular
Posts: 47
Joined: Wed May 23, 2018 4:47 pm
Contact:

Problem with variables, please help! [SOLVED]

#1 Post by tim640 »

I am honestly confused. Tried to get around this a few different ways, but always end up with the same problem. Will really appreciate ideas :(

So i have an in-game map with quests to select. I define them with variables, something like

Code: Select all

        if persistent.quest1 == "active":
            imagebutton idle "quest1emblem.png"
        elif persistent.quest1 == "finished":
            None
The problem i encountered is with saving and loading. Let's say we selected a quest, and it started:

Code: Select all

        $ persistent.quest1 = "active"
        (quest code here, blah blah, dialogue)
        $ persistent.quest1 = "finished"
Now let's say, player saves somewhere on the map BEFORE the quest, then FINISHES the quest, which sets the persistent.quest1 from "active" to "finished". Now, he loads the save that was BEFORE the quest. But since the quest was finished, persistent.quest1 was set to "finished", and despite the save being made BEFORE the quest, it's gonna look like the quest was taken. What should i do?.. I guess i need a variable that is associated with a certain point of the game, not persistent, but i can't find info on those. How do i do that?..

Another example of this is going back to the map from an active quest. I want to disable the option to return to the map at some points, i made a menu option that goes like this:

Code: Select all

if persistent.map == "1" or persistent.map == "0":
    if renpy.get_screen("map"):
        textbutton _("MAP") action Return()
    elif persistent.map == "0":
        textbutton _("MAP") action Notify("You can't return to the map right now")
    elif persistent.map == "1":
        textbutton _("MAP") action Confirm("Are you sure you want to return to the map?", yes=Call("map"), no=None)                
So, if the player is already on the map, it just closes the menu, if persistent.map == "1", it's going ask for a confirmation, and if it's "0", it's going to show a notification that you can't go to the map currently. I want to use it in important scenes and the very beginning of the game.
But here i am encountering the same problem as i do with quests. Say i have the quest code

Code: Select all

        $ persistent.map == "1"
        (quest starts here)
        $ persistent.map == "0"
        (important scene starts here, so you can't exit to the map anymore)
        $ persistent.map == "1"
        (scene ends, and map is available again)
And now let's say player saved during an important scene, when persistent.map was set to "0". Then scene ends, and persistent.map sets to "1" again. Now, if the player will load the save file that was made during the important scene, he will be able to exit to the map, anyway, because the persistent was already set to "1" and the save was made after the variable was set to "0".

What do i do? Thank you in advance!
Last edited by tim640 on Sun Feb 10, 2019 2:39 pm, edited 1 time in total.

User avatar
tim640
Regular
Posts: 47
Joined: Wed May 23, 2018 4:47 pm
Contact:

Re: Problem with variables, please help!

#2 Post by tim640 »

...i am very sorry, nvm.
For the ones who might be a bit blind like i am, here's stuff to read:
https://www.renpy.org/doc/html/python.html
https://www.renpy.org/doc/html/conditional.html
This can be used in Menus as well and unlike persistent variables will be dynamic and associated with certain moments of the game. :oops:

Post Reply

Who is online

Users browsing this forum: Andredron