Trying to add Notifications to my game

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
arlj11
Regular
Posts: 28
Joined: Mon Jan 06, 2020 12:30 pm
Projects: 4Wins
Deviantart: arlj11
Github: arlj11
Contact:

Trying to add Notifications to my game

#1 Post by arlj11 »

Like the title says, I'm trying to add Notifications to my game.

I have an Extras area on my Main Menu and I want to notify my players when they have unlocked bonus content. I also want the notification to show only once.

There are a lot of variables though. Mostly if they have to have seen certain pictures or played other extras.

The problem is if I do it this way on the Extras screen.

Code: Select all

    if persistent.credits_seen:
        $ renpy.notify("Inside the Character Studio has been unlocked")
        textbutton "Introduction" action Replay("ICSIntro", locked=False)
    else:
        text "The episode is not unlocked yet."
The notification loops continuously on the Main Menu when the conditions are met.

I have tried grouping them in one label and call that label at the end of the game or when I know an unlock could occur. With a persisent that turns true after the notification has triggered, like this.

Code: Select all

   if persistent.credits_seen or persistent.IntroUnlocked == False:
        $ renpy.notify("Inside the Character Studio has been unlocked")
        $ persistent.IntroUnlocked = True
Or this way.

Code: Select all

    if persistent.credits_seen and persistent.IntroUnlocked == False:
        $ renpy.notify("Inside the Character Studio has been unlocked")
        $ persistent.IntroUnlocked = True
But I then had to create another label that basically checks if the persistent data exist in the first place and if not creates it.

Code: Select all

label PersistentCheck:

    if not persistent.IntroUnlocked:
        $ persistent.IntroUnlocked = False
I put that one in my splashscreen label so it runs at the very start of the game.

Is there an easier way of do all this that doesn't rely on so much persistent data?

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Trying to add Notifications to my game

#2 Post by hell_oh_world »

You dont need to set a persistent variable to False, is not necessary. Any persistent variable that is referenced for the very first time always defaults to `None`.
And you can directly use that value as a condition.

Code: Select all

if not persistent.unlocked: # is very much the same as saying... persistent.unlocked == False
  pass
  # then don't show this, that, etc...`.

arlj11
Regular
Posts: 28
Joined: Mon Jan 06, 2020 12:30 pm
Projects: 4Wins
Deviantart: arlj11
Github: arlj11
Contact:

Re: Trying to add Notifications to my game

#3 Post by arlj11 »

Will "not" work next to an or/and?

Example:

Code: Select all

   if persistent.credits_seen or not persistent.IntroUnlocked:
        $ renpy.notify("Inside the Character Studio has been unlocked")
        $ persistent.IntroUnlocked = True
        
   if persistent.credits_seen and not persistent.IntroUnlocked:
        $ renpy.notify("Inside the Character Studio has been unlocked")
        $ persistent.IntroUnlocked = True
Sorry if I sound like a newbie.

jeffster
Veteran
Posts: 384
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Trying to add Notifications to my game

#4 Post by jeffster »

"And" and "or" combine any logical conditions. See a few interesting details in Python tutorial:

https://docs.python.org/3/tutorial/data ... conditions

(When you see differences between Python 3 and Python 2.7, note that current Ren'Py version might still run on Python 2.7 but the transition to Python 3 is in progress, so it's recommended to use code compatible both with 2.7 and 3.)

Post Reply

Who is online

Users browsing this forum: Google [Bot], piinkpuddiin