Page 1 of 1

Trying to add Notifications to my game

Posted: Tue Sep 21, 2021 6:06 pm
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?

Re: Trying to add Notifications to my game

Posted: Wed Sep 22, 2021 12:14 am
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...`.

Re: Trying to add Notifications to my game

Posted: Wed Sep 22, 2021 12:28 am
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.

Re: Trying to add Notifications to my game

Posted: Wed Sep 22, 2021 3:51 am
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.)