Function doesn't update Sensitive conditional [Solved]

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
terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Function doesn't update Sensitive conditional [Solved]

#1 Post by terrordoll »

I have a screen that I define like this:

Code: Select all

screen mixing_screen():
    imagebutton idle "mixer_left_idle_image" hover "mixer_left_hover_image" action [SetVariable('mixer_left', helditem), Function(MixAdd)] sensitive mixer_left == "none" xpos 400 ypos 0
    imagebutton idle "mixer_center_idle_image" hover "mixer_center_hover_image" action [SetVariable('mixer_center', helditem), Function(MixAdd)] sensitive mixer_center == "none" xpos 750 ypos 0
    imagebutton idle "mixer_right_idle_image" hover "mixer_right_hover_image" action [SetVariable('mixer_right', helditem), Function(MixAdd)] sensitive mixer_right == "none" xpos 1100 ypos 0
    imagebutton auto "images/mixer_button_on_%s.png" action Return() sensitive mixer_full == True xpos 1200 ypos 700
    imagebutton auto "images/mixer_button_purge_%s.png" action Function(MixPurge) sensitive mixer_empty == False xpos 1200 ypos 850
Each of the three mix buttons fires off a function that should eventually keep track of what was added to the machine. It also toggles the two bools for whether the maching is not empty and when its full (mixer_empty and mixer_full). Right now it's just hardwired to flip the bools while I try to figure out my issue.

Code: Select all

    def MixAdd():
        mixer_full = True
        mixer_empty = False
        renpy.log("mix add fired")
The log seems to fire fine but my "sensitive" conditional isn't recalculating. If I change one of the Imagebuttons to this then the sensitive portion works just fine

Code: Select all

    imagebutton idle "mixer_left_idle_image" hover "mixer_left_hover_image" action [SetVariable('mixer_left', helditem), SetVariable('mixer_full', True)] sensitive mixer_left == "none" xpos 400 ypos 0
    imagebutton auto "images/mixer_button_on_%s.png" action Return() sensitive mixer_full == True xpos 1200 ypos 700
It seems like there is some issue with trying to manipulate the variables in the function that is causing an issue. I found this thread (viewtopic.php?f=8&t=30849) and thought maybe I'd found a solution but no dice.

Any thoughts?
Last edited by terrordoll on Thu May 25, 2017 6:04 pm, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Imagebutton Function doesn't update Sensitive conditiona

#2 Post by trooper6 »

terrordoll wrote: Each of the three mix buttons fires off a function that should eventually keep track of what was added to the machine. It also toggles the two bools for whether the maching is not empty and when its full (mixer_empty and mixer_full). Right now it's just hardwired to flip the bools while I try to figure out my issue.

Code: Select all

    def MixAdd():
        mixer_full = True
        mixer_empty = False
        renpy.log("mix add fired")
That isn't working because functions are there own space. What you've done there is create a brand new variable called mixer_full and mixer_empty that only exists within that function and given them some values. To access the variables that the rest of the game is using, you need to tell the function that. So change your function like so:

Code: Select all

    def MixAdd():
        global mixer_full
        global mixer_empty
        mixer_full = True
        mixer_empty = False
        renpy.log("mix add fired")
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Imagebutton Function doesn't update Sensitive conditiona

#3 Post by terrordoll »

Tried to do this a little cleaner and hit another bump.

Code: Select all

screen mixing_screen():
    imagebutton idle "mixer_left_idle_image" hover "mixer_left_hover_image" action SetVariable('mixture[0]', helditem) sensitive mixture[0] == None xpos 400 ypos 0
    imagebutton idle "mixer_center_idle_image" hover "mixer_center_hover_image" action SetVariable('mixture[1]', helditem) sensitive mixture[1] == None xpos 750 ypos 0
    imagebutton idle "mixer_right_idle_image" hover "mixer_right_hover_image" action SetVariable('mixture[2]', helditem) sensitive mixture[2] == None xpos 1100 ypos 0
    imagebutton auto "images/mixer_button_on_%s.png" action Return() sensitive None in mixture == False xpos 1200 ypos 700
    imagebutton auto "images/mixer_button_purge_%s.png" action Function(MixPurge) sensitive mixture == False xpos 1200 ypos 850
SetVariable doesn't want to play well with my array. Trying SetField now but I'm not too hopeful....

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Imagebutton Function doesn't update Sensitive conditiona

#4 Post by terrordoll »

trooper6 wrote:
terrordoll wrote: Each of the three mix buttons fires off a function that should eventually keep track of what was added to the machine. It also toggles the two bools for whether the maching is not empty and when its full (mixer_empty and mixer_full). Right now it's just hardwired to flip the bools while I try to figure out my issue.

Code: Select all

    def MixAdd():
        mixer_full = True
        mixer_empty = False
        renpy.log("mix add fired")
That isn't working because functions are there own space. What you've done there is create a brand new variable called mixer_full and mixer_empty that only exists within that function and given them some values. To access the variables that the rest of the game is using, you need to tell the function that. So change your function like so:

Code: Select all

    def MixAdd():
        global mixer_full
        global mixer_empty
        mixer_full = True
        mixer_empty = False
        renpy.log("mix add fired")
Haha, so it was a scope issue the whole time? Geez. Thanks again Trooper, you're the best!

Post Reply

Who is online

Users browsing this forum: Google [Bot], voluorem