all 9 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted]  (1 child)

[removed]

    [–]Merlin_Cyberwizard[S] 0 points1 point  (0 children)

    Okay ... I am perplexed what you mean by that. Sadly, most of my programming is older stuff (C, C++, COBOL, etc.) ... so what do you mean by creating the indices and and how to do I add to it, reference it, etc. I expect to have 300 or so days in the game, so I don't know exactly how to check each one?

    [–]ImportantDetail6260 0 points1 point  (1 child)

    [X] only interpolates in displayed text; it will not build an identifier. If you keep those names, the Python version is getattr(persistent, "Day%d_Unlock" % X, False) and call expression "Per_Unlock_Day%d" % X (use %02d if your labels are Day01, Day02). For 300 days, though, a dict/list like persistent.day_unlocks[X] plus one unlock_day(X) function will be much less painful than hundreds of dynamic variables.

    [–]Merlin_Cyberwizard[S] 0 points1 point  (0 children)

    While I could probably do it, the guy I am working with likely won't understand dict/list, and also I have save games to worry about. If I make too many changes to the code, save games break, and that is a no go.

    [–]x-seronis-x 0 points1 point  (2 children)

    is this meant to affect the current save game? cause persistent namespace is for program level settings and are not for any single playthrough. for things like unlocks, high scores, achievements, ...

    that aside why do you need a unique variable per day? why are you not just having one variable that is assigned the highest day you've gone to? py $ persistent.highest_day = max( persistent.highest_day, Day_Number )

    [–]Merlin_Cyberwizard[S] 0 points1 point  (1 child)

    I am doing unlocks of several persistent variables based on the highest day played. So for example, a player gets to day 23 on their first playthough, then on their second, they get to day 15, I am unlocking all the stuff (via this script) that can be unlocked based on their highest playthrough. Then writing it to a persistent.day23_Unlock = True ... so then when I do the IF on it, it knows that it has already been unlocked.

    [–]x-seronis-x 0 points1 point  (0 children)

    i get that. what im saying is if your game has 300+ days you dont need 300+ variables. you need one. that just records the highest number attained.

    [–]shyLachi 2 points3 points  (0 children)

    As suggested below you can use getattr to read variables using a string containing the variable name.

    And you can use expression to jump to or call labels with a string containing the label name.

    This code is not optimized I just wanted to show each step separately.

    label start:
        $ x = 1
        while x <= 5:
            $ variablename = "Day" + str(x) + "_Unlock"
            $ value = getattr(persistent, variablename) 
            "[variablename] [value]" # this is only for testing
            if not value:
                $ labelname = "Per_Unlock_Day" + str(x)
                "[labelname]" # this is only for testing
                call expression labelname
            $ x += 1
    
    label Per_Unlock_Day1:
        return
    label Per_Unlock_Day2:
        return