Jump to content

Renpy help


pnadadeath

Recommended Posts

Hi,

I was wondering if anyone could perhaps tell me where I am being dumb.  I want a button to add to a "completion" value, but for the life of me I can not figure out where it is not working.  I have flat out just copied the code from the tutorials trying to make this work:

init python:
    showcompletion= False
    completion = 0
    def display_completion():
        if showcompletion:   
            ui.frame() #This is optional. It adds a frame around the text.
            ui.text("Completion: %d" %completion)
    config.overlay_functions.append(display_completion)

 

my python init for the "completion" value from https://www.renpy.org/wiki/renpy/doc/cookbook/Simple_Onscreen_Inventory

 

and here is the button:

    screen P_tube_options00:
        modal False
        imagebutton:
            xpos 0 ypos 500
            idle "idle.png"
            hover "hover_text.png"
            action [Hide("imagebutton")]
        imagebutton:
            xpos 180 ypos 180
            idle "blank.png"
            hover "hover.png"
            action [Jump("P_tube00_description"), SetVariable("completion",completion+1), SetVariable('T_options00a',True)]
            

This is from https://lemmasoft.renai.us/forums/viewtopic.php?f=8&t=9412

 

However, whenever I print the "completion" afterward, it is still 0.  If I hard code a $completion+=1 in the main script I get the "completion" counter to increase by one.  However, if I put  SetVariable("completion",completion+=1), or $completion+=1 in the imagebutton tabs, I get an error.

 

I know I am missing something very simple and sorry if it is not explained well.

Link to comment
Share on other sites

Would need some more code I think. It's probably going to do with scope, and the completion you print is likely the one you set at the init, where you set it to 0. Or maybe it is working but you're just setting it back to 0 each time you try to display it.

 

Edit: After playing with it a bit, yeah it's to do with scope. This works for me in my script file: http://pastebin.com/HpXcv9Ur 

The variable can be set and accessed from your script if you put the screen in your script file directly. You can set it in your init python section too and it works all the same.

If you want it inside the screens file instead though, you'll probably want to look at using Return(completion) rather than SetVariable and then in your script you can use completion = renpy.call_screen(" P_tube_options00"). It depends how all your stuff is setup. I think the easiest way is just put the screen in your script file.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...