Transform not changing to reflect change in variable

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
MaryTheMagician
Newbie
Posts: 1
Joined: Mon Apr 02, 2018 10:19 pm
Contact:

Transform not changing to reflect change in variable

#1 Post by MaryTheMagician »

Hello,

I'm having trouble with changing the behavior of a transform based on a store variable.

I've been writing a point-and-click game that uses an in-game "phone" for some gameplay elements. This phone is shown and hidden using a button in the corner of the screen. There are multiple circumstances under which the phone should be hidden.

When the phone is hidden in order to display other UI elements, it should hide itself with no transform animation. When the phone is hidden because the user clicked on an area of the screen outside of the phone, the phone should play a short transform animation that minimizes it to the corner of the screen.
There is a variable that keeps track of whether or not the phone is open, called 'phone_open'. When the button is clicked that causes the phone to be displayed, this variable is set to 1.

The player's mouse position is detected using an invisible displayable (based on code provided in viewtopic.php?p=253647), which is added to every screen. (This displayable also handles some functions related to the game's inventory.)
When the phone is displayed, and the mouse is clicked outside of the area of the phone, this displayable sets phone_open to 0, and then hides the phone.

The phone's transform should cause the phone's "hide" animation to change, based upon whether phone_open is set to 1 or 0. My problem is that this transform always behaves as if phone_open is set to 1, even though, when the phone is hidden by clicking outside of the phone, phone_open is set to 0 before the phone is hidden. I am not sure why this is happening.

Relevant code:

Displayable:

Code: Select all

init python:
    store.phone_open = 0
    
    class getMousePosition(renpy.Displayable):
    
        def __init__(self):
            renpy.Displayable.__init__(self)
            
        def event(self, ev, x, y, st):
            import pygame
            if ev.type == pygame.MOUSEBUTTONDOWN:
                if store.phone_open == 1:
                    if (x <= 722) or (x >= 1198):
                        store.phone_open = 0
                        #When the phone is hidden here, the animation should be played.
                        renpy.hide("phone", layer="screens")  
                        
        def render(self, width, height, st, at):
            return renpy.Render(0, 0)
            
    store.mousePosition= getMousePosition()
    
    def checkEvent():
        ui.add(mousePosition)
            
    config.overlay_functions.append(checkEvent)
Phone transform:

Code: Select all

transform phone_pickup:
    on show:
        alpha 100 yalign 1.0 zoom 0.2
        easein 0.3 xalign 0.5 zoom 1
    on hide:
        easeout 0.3 zoom (0.2 if (phone_open == 0) else 1) xoffset (-902 if (phone_open == 0) else 0) yoffset (-25 if (phone_open == 0) else 0)
        alpha 0
Phone screen:

Code: Select all

screen phone:
    image "phone/phonehomenoclock.png" at phone_pickup
    #This button shows another screen. When this button is clicked, the phone should hide without playing an animation, then show another screen. This works correctly.
    button:
        #146 886 
        area(868, 920, 77, 77)
        action [Hide("phone"), Show("phonemap")]
Imagebutton that shows the phone (added to many screens):

Code: Select all

    imagebutton idle "phone/phonesmall.png" xpos 10 ypos 850 focus_mask True action [SetVariable("phone_open", 1), Show("phone")]
Sorry if something similar has been asked before.

Post Reply

Who is online

Users browsing this forum: No registered users