[SOLVED]Changing a variable in screens.rpy

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
Kinmoku
Miko-Class Veteran
Posts: 515
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED]Changing a variable in screens.rpy

#1 Post by Kinmoku » Mon May 11, 2020 12:25 pm

Hi all. I want to have a notification icon appear when there are messages or notifications for the player character to read. These are story based and set manually by me in the script. However, my current code doesn't appear to update my conditional statement.

Here's my code in script.rpy:

Code: Select all

image notification = "images/notification.png"

transform menu_notifications:
    xanchor 0.0 xpos 174
    yanchor 0.0 ypos 756
    

label start:

    # etc
    
    $ notification_on = True  ## to show the image in the screen
    
    show screen shark_userpage
        
    pause
In screens.rpy, my "mock interfaces" are set up like this:

Code: Select all

screen shark_interface:
    modal True 
    add "interface"
    
    imagebutton idle Solid("#0000", xysize=(250, 200)) clicked [hide_screens(), Show("shark_userpage")] xpos 0 ypos 144 focus_mask None #[hide_screens, Show("shark_userpage")] xpos 0 ypos 144 focus_mask None
    imagebutton idle Solid("#0000", xysize=(250, 200)) clicked [hide_screens(), Show("shark_communities")] xpos 0 ypos 344 focus_mask None#[hide_screens, Show("shark_communities")] xpos 0 ypos 344 focus_mask None
    imagebutton idle Solid("#0000", xysize=(250, 200)) clicked Jump("message_inbox") xpos 0 ypos 544 focus_mask None#[hide_screens, Show("shark_messages")] xpos 0 ypos 544 focus_mask None
    imagebutton idle Solid("#0000", xysize=(250, 200)) clicked [hide_screens(), Show("shark_notifications")] xpos 0 ypos 744 focus_mask None#[hide_screens, Show("shark_notifications")] xpos 0 ypos 744 focus_mask None
    
    if notification_on == True: ## if the notification is on, the icon appears in the specified location - this works
        add "notification" at menu_notifications

# One of my mock interface screens below. I want it to hide the icon when selected, as the notifications have then been seen.        
        
screen shark_notifications:
    $ notification_on = False ## this doesn't appear to register, as the variable viewer says it's still "True" and the image remains.
    
    modal True 
    tag sharkmenu
    use shark_interface
    
    add "images/menu_on.png" xpos 0 ypos 744
    
    text _("Your Notifications") color "#000000" xpos 30 ypos 16
I could move "$ notification_on = False" to the next part of dialogue, but a lot of my story is told within screens/ the mock interface, so it maybe a while until the notification icon disappears.

Does anyone know what I'm doing wrong?
Last edited by Kinmoku on Tue May 12, 2020 3:44 am, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 718
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Changing a variable in screens.rpy

#2 Post by gas » Mon May 11, 2020 12:41 pm

You want for a picture to appear along the others if a variable is True. Then when you click on the button, the variable turn to False.

You must add the action to the button that open the second screen. Don't set it when you show the second screen.

Code: Select all

imagebutton idle Solid("#0000", xysize=(250, 200)) clicked [hide_screens(), SetVariable("notification_on", False), Show("shark_notifications")] xpos 0 ypos 744 focus_mask None
Remove one line:

Code: Select all

screen shark_notifications:
    $ notification_on = False ## << remove this one !!
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll be not notified about.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Kinmoku
Miko-Class Veteran
Posts: 515
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Changing a variable in screens.rpy

#3 Post by Kinmoku » Tue May 12, 2020 3:44 am

gas wrote:
Mon May 11, 2020 12:41 pm
You want for a picture to appear along the others if a variable is True. Then when you click on the button, the variable turn to False.

You must add the action to the button that open the second screen. Don't set it when you show the second screen.

Code: Select all

imagebutton idle Solid("#0000", xysize=(250, 200)) clicked [hide_screens(), SetVariable("notification_on", False), Show("shark_notifications")] xpos 0 ypos 744 focus_mask None
Remove one line:

Code: Select all

screen shark_notifications:
    $ notification_on = False ## << remove this one !!
Ah thank you so much! I don't know why I didn't think of that >_< I blame end-of-day headache lol.

Thanks again :D

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]