Page 1 of 1

[SOLVED]Changing a variable in screens.rpy

Posted: Mon May 11, 2020 12:25 pm
by Kinmoku
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?

Re: Changing a variable in screens.rpy

Posted: Mon May 11, 2020 12:41 pm
by gas
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 !!

Re: Changing a variable in screens.rpy

Posted: Tue May 12, 2020 3:44 am
by Kinmoku
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