Button with my own function

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
sashaaero
Regular
Posts: 45
Joined: Mon Jul 13, 2015 6:08 pm
Projects: Everlasting Cold
Organization: OverDream Development
Github: sashaaero
Skype: sashaaero
Contact:

Button with my own function

#1 Post by sashaaero »

I have following code block

Code: Select all

python:
        load = 1
        
        def set_load(l):
            load = l
        
        def get_load():
            return load

 for i in range(10):
    button:
        action FileAction(i)
        #action set_load(i)
With 'FileAction(i)' button are working. If i set my own function there - buttons not even clicking or hovering.
What's wrong here?

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: Button with my own function

#2 Post by trooper6 »

Are you coming from Java? You don't need set and get functions. You can just access the variable directly in Python.

In this case you'd want to use the SetVariable screen action for your button. It is noted here:
http://www.renpy.org/doc/html/screen_actions.html

I can't give you an example in code because I am in a cafe and don't have access to my computer.
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

User avatar
sashaaero
Regular
Posts: 45
Joined: Mon Jul 13, 2015 6:08 pm
Projects: Everlasting Cold
Organization: OverDream Development
Github: sashaaero
Skype: sashaaero
Contact:

Re: Button with my own function

#3 Post by sashaaero »

trooper6 wrote:Are you coming from Java? You don't need set and get functions. You can just access the variable directly in Python.

In this case you'd want to use the SetVariable screen action for your button. It is noted here:
http://www.renpy.org/doc/html/screen_actions.html

I can't give you an example in code because I am in a cafe and don't have access to my computer.
That

Code: Select all

$ store.load = 1  

for i in range(10):
                button:
                    #action FileAction(i)
                    action SetVariable("load", i)
does nothing :(


Okay. Actually, maybe i'm doing it wrong.
I just want to have a list of saving, when you click on it, screenshot of saving is appearing in right side of screen and there is a button "Load".

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Button with my own function

#4 Post by orz »

An action on a button should only take a ScreenAction object.

http://www.renpy.org/doc/html/screen_actions.html

If you want it to just run your python function, use the Function() action:
http://www.renpy.org/doc/html/screen_ac ... l#Function

synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Re: Button with my own function

#5 Post by synedraacus »

If you want it to just run your python function, use the Function() action:
Or, better yet, define the custom Action. You'll get checks for sensitive/insensitive state for your buttons.

User avatar
sashaaero
Regular
Posts: 45
Joined: Mon Jul 13, 2015 6:08 pm
Projects: Everlasting Cold
Organization: OverDream Development
Github: sashaaero
Skype: sashaaero
Contact:

Re: Button with my own function

#6 Post by sashaaero »

Okay. I change my question to...
Did anyone have source code of this screen?
http://www.renpy.org/wiki/layout.scrolling_load_save

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: Button with my own function

#7 Post by trooper6 »

That is from the wiki and it is out of date (that page is 7 years old!), you should use the current documentation.

I can't help you much with load/save stuff as that is not anything I've experimented with yet...but I'd look in the screens.rpy file and really study what is there. Also look at the screen language documentation more generally.
Also, you might want to do a search here in the forum Question Board for save and image or save and screenshot or save and thumbnail because I know people have asked questions like that before.

For example, here are a few threads that might be useful for you to look over:
http://lemmasoft.renai.us/forums/viewto ... +thumbnail
http://lemmasoft.renai.us/forums/viewto ... 51&t=14237
http://fuckyeahrenpy.tumblr.com/post/91 ... eload-menu

Otherwise, you'll probably need one of the more advanced programmers to stop by this thread and help you out.
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

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Button with my own function

#8 Post by SinnyROM »

I agree with trooper6, avoid the wiki like the plague. There are more outdated articles than updated so you're better off looking at the current documentation or asking.

If you're looking for how to have a selectable save/load screen that displays the screenshot of the currently selected save, then I have this snippet from when I helped another person to achieve the same thing. https://bitbucket.org/snippets/sinnysta ... matic-save This has the automatically generated file description function which is optional.

If it's the scrolling save list, then it's a case of wrapping the elements in a scrollable viewport: http://www.renpy.org/doc/html/screens.html#viewport

I can help you with implementing it later on as I have to go to work now, but feel free to explain more on what you want to achieve.

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Button with my own function

#9 Post by DragoonHP »

I don't have the source code of that layout but here is a screen version of it: http://pastebin.com/qCbSwK8j

User avatar
sashaaero
Regular
Posts: 45
Joined: Mon Jul 13, 2015 6:08 pm
Projects: Everlasting Cold
Organization: OverDream Development
Github: sashaaero
Skype: sashaaero
Contact:

Re: Button with my own function

#10 Post by sashaaero »

DragoonHP wrote:I don't have the source code of that layout but here is a screen version of it: http://pastebin.com/qCbSwK8j
This is it!
But last question, how can I set size for

Code: Select all

add screenshot_image
?
Cause it's very small.

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Button with my own function

#11 Post by orz »

Make a fixed: or something like it that contains it.

Or you could try manipulating the displayable/image directly. Probably something with an image manipulator, if you go that route.

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Button with my own function

#12 Post by DragoonHP »

Change these values

Code: Select all

    config.thumbnail_height = 180
    config.thumbnail_width = 320

User avatar
sashaaero
Regular
Posts: 45
Joined: Mon Jul 13, 2015 6:08 pm
Projects: Everlasting Cold
Organization: OverDream Development
Github: sashaaero
Skype: sashaaero
Contact:

Re: Button with my own function

#13 Post by sashaaero »

Thanks everyone for help! I did all I want :)
Image

Post Reply

Who is online

Users browsing this forum: Ocelot, piinkpuddiin, snotwurm