Unlockable second campaign.

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
NadOtavlas
Regular
Posts: 37
Joined: Sat Apr 21, 2018 3:46 am
Contact:

Unlockable second campaign.

#1 Post by NadOtavlas » Sat Mar 06, 2021 9:56 am

So in my game I want there to be an unlockable second campaign after getting all of the endings in the game. This campaign is selectable as a on the main menu. I know if I want to program something like this I need to use persistent data but I don't actually know how it works. Can someone explain? Also can someone explain how to change the main menu to include this option?

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Unlockable second campaign.

#2 Post by _ticlock_ » Sat Mar 06, 2021 10:54 am

Hi, NadOtavlas,

You need persistent flags for each ending and optionally variable persistent.campaign2_unlocked.

Code: Select all

default persistent.ending_1 = False
default persistent.ending_2 = False
default persistent.campaign2_unlocked = False
Now when you reach an ending you change the corresponding variable to True and check if all endings are unlocked.

Code: Select all

label ending_1:
    ...
    $ persistent.ending_1 = True
    call check_campaign2_unlock
    return
    
label check_campaign2_unlock:
    if persistent.ending_1 and persistent.ending_2:
        $ persistent.campaign2_unlocked = True
    return
A simple example to add a button to the main menu:
In screens.rpy find screen navigation and add your button there:

Code: Select all

screen navigation():
    vbox:
        ...
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Campaign 2"):
            if persistent.campaign2_unlocked:
                action Start('label_campaign2')
However, a better way is to use set to store the flags for endings:

Code: Select all

default persistent.endings = set()
label ending_1:
    ...
    $ persistent.endings.add("end_1")
    return
Then you can use len(persistent.endings) to see if all endings are reached: For 2 endings you will have:

Code: Select all

screen navigation():
    vbox:
        ...
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Campaign 2"):
            if len(persistent.endings) == 2:
                action Start('label_campaign2')

Post Reply

Who is online

Users browsing this forum: Bing [Bot], enaielei, Google [Bot]