Giving two actions to an imagebutton [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
User avatar
Meg'
Regular
Posts: 185
Joined: Tue Sep 27, 2011 10:37 am
Projects: Anges Démoniaques, Gang (Alex & Hugo), Le passé dans les veines
Location: France
Contact:

Giving two actions to an imagebutton [SOLVED]

#1 Post by Meg' » Fri Feb 19, 2016 12:39 pm

Hello!

I'm using imagebuttons for the main menu of my game (yes, imagebuttons are as cool as the tutorial said :mrgreen: ). I was wondering if I could add more than one action to an imagebutton?

My code for the imagebutton which is concerned:

Code: Select all

    imagebutton auto "gui/main_start_%s.png" xpos 450 ypos 300 action Start() at main_eff1
And the full code of my main menu:

Code: Select all

screen main_menu:

    tag menu

    add "main_fd.jpg"
    
    add "gui/forme1.png" xpos 333 ypos 520 at main_eff4
    
    add "gui/forme1.png" xpos 805 ypos 520 at main_eff5    

    imagebutton auto "gui/main_start_%s.png" xpos 450 ypos 300 action Start() at main_eff1

    imagebutton auto "gui/main_config_%s.png" xpos 800 ypos 500 action ShowMenu('preferences') at main_eff2

    imagebutton auto "gui/main_extras_%s.png" xpos 340 ypos 500 action Start('extras') at main_eff3
    
init -2:
    transform main_eff1:
        zoom 0.5
        easein 0.4 zoom 1.0
    transform main_eff2:
        zoom 0.5
        easein 0.8 zoom 1.0
    transform main_eff3:
        zoom 0.5
        easein 1.2 zoom 1.0
    transform main_eff4:
        zoom 0.5
        easein 1.2 zoom 1.0 rotate 360.0
    transform main_eff5:
        zoom 0.5
        easein 1.2  zoom 1.0 rotate 360.0
When clicked for the first time, it'll start the game. But if the player has already played a little (and so the game has been saved), when returning to the main menu and clicking on "start" will continue the game where it was left.

How can I do that?

Thanks in advance! :D
Last edited by Meg' on Mon Feb 22, 2016 2:41 am, edited 1 time in total.

User avatar
Winterslice
Veteran
Posts: 228
Joined: Mon Sep 28, 2015 3:51 am
Completed: The Next World, Golem Creation Kit
Organization: Illuminated Games
Contact:

Re: Giving two actions to an imagebutton

#2 Post by Winterslice » Fri Feb 19, 2016 1:31 pm

I'm using imagebuttons for the main menu of my game (yes, imagebuttons are as cool as the tutorial said :mrgreen: ). I was wondering if I could add more than one action to an imagebutton?
You can, by enclosing your actions in a list, separating the actions with a comma. For example:

action [ SetVariable("variable", True), Jump("label") ]

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Giving two actions to an imagebutton

#3 Post by xela » Fri Feb 19, 2016 2:17 pm

You can just separate them with a comma.
Like what we're doing? Support us at:
Image

User avatar
Winterslice
Veteran
Posts: 228
Joined: Mon Sep 28, 2015 3:51 am
Completed: The Next World, Golem Creation Kit
Organization: Illuminated Games
Contact:

Re: Giving two actions to an imagebutton

#4 Post by Winterslice » Fri Feb 19, 2016 2:25 pm

xela wrote:You can just separate them with a comma.
True. For my part, although they aren't strictly necessary, list brackets help me keep them organised and separate from hover/unhover actions, etc..

User avatar
Meg'
Regular
Posts: 185
Joined: Tue Sep 27, 2011 10:37 am
Projects: Anges Démoniaques, Gang (Alex & Hugo), Le passé dans les veines
Location: France
Contact:

Re: Giving two actions to an imagebutton

#5 Post by Meg' » Fri Feb 19, 2016 3:35 pm

xela wrote:You can just separate them with a comma.
Like that? ==>

Code: Select all

    imagebutton auto "gui/main_start_%s.png" xpos 450 ypos 300 action Start(), ShowMenu("load") at main_eff1
But even if the code above was correct, it wouldn't work because I don't have a save/load screen (it will be a free to play, so no saving). I want to use the auto-saving function of ren'py. How can I call the auto-save made by ren'py using that code?
Winterslice wrote:
I'm using imagebuttons for the main menu of my game (yes, imagebuttons are as cool as the tutorial said :mrgreen: ). I was wondering if I could add more than one action to an imagebutton?
You can, by enclosing your actions in a list, separating the actions with a comma. For example:

action [ SetVariable("variable", True), Jump("label") ]
Yup but if it jumps to a label, it won't work either. As I explained above, I don't have a screen for saving or loading.

User avatar
Winterslice
Veteran
Posts: 228
Joined: Mon Sep 28, 2015 3:51 am
Completed: The Next World, Golem Creation Kit
Organization: Illuminated Games
Contact:

Re: Giving two actions to an imagebutton

#6 Post by Winterslice » Fri Feb 19, 2016 3:42 pm

Meg' wrote:Yup but if it jumps to a label, it won't work either. As I explained above, I don't have a screen for saving or loading.
That was just an example of how to structure multiple actions. Nothing to do with saving.

If you want to create your own autosave/checkpoint system, there's this:
http://www.renpy.org/doc/html/save_load_rollback.html

You can use renpy.save and renpy.load at will, so that's one way to do it.

Shakezula
Regular
Posts: 67
Joined: Wed May 20, 2015 8:01 pm
Contact:

Re: Giving two actions to an imagebutton

#7 Post by Shakezula » Fri Feb 19, 2016 4:16 pm

If you want to use screen language to force an autosave, you can do it like this:

action Function(renpy.force_autosave)


That would be a combination of screen language call function action:: Function(callable, *args, **kwargs)
And renpy's force autosave regardless of has autosave setting function:: renpy.force_autosave(take_screenshot=False).


Sidenote: Snce you're going to provide all saving manually, you should probably also cut out all renpy's manual autosaving with this code block:

Code: Select all

init python: #python early can also be used here
    config.has_autosave = False
    config.autosave_on_choice = False
    config.autosave_on_quit = False
Lastly, I also STRONGLY recommend as Winterslice did that you set your multiple screen actions to be a traditional list with [square, brackets, seperated, by, commas]. It will make your code that much more readable (as you add hover states and other screen properties to your imagebuttons) and quickly readable code is the python way. :mrgreen:

User avatar
Meg'
Regular
Posts: 185
Joined: Tue Sep 27, 2011 10:37 am
Projects: Anges Démoniaques, Gang (Alex & Hugo), Le passé dans les veines
Location: France
Contact:

Re: Giving two actions to an imagebutton

#8 Post by Meg' » Sat Feb 20, 2016 2:43 am

Thank you for your advices, everyone! :D

I'm still trying to implement what you said.
Shakezula wrote:If you want to use screen language to force an autosave, you can do it like this:

action Function(renpy.force_autosave)


That would be a combination of screen language call function action:: Function(callable, *args, **kwargs)
And renpy's force autosave regardless of has autosave setting function:: renpy.force_autosave(take_screenshot=False).


Sidenote: Snce you're going to provide all saving manually, you should probably also cut out all renpy's manual autosaving with this code block:

Code: Select all

init python: #python early can also be used here
    config.has_autosave = False
    config.autosave_on_choice = False
    config.autosave_on_quit = False
Lastly, I also STRONGLY recommend as Winterslice did that you set your multiple screen actions to be a traditional list with [square, brackets, seperated, by, commas]. It will make your code that much more readable (as you add hover states and other screen properties to your imagebuttons) and quickly readable code is the python way. :mrgreen:
I don't intend to use a checkpoint system, maybe I wasn't clear enough. I saw when playing the game on my phone, that it could be quit and still continue from where it was left the last time I closed the app (that's what I was talking about when I mentioned ren'py auto-saving function).

I tried to do it like this:

Code: Select all

    imagebutton auto "gui/main_start_%s.png" xpos 450 ypos 300  action [ SetVariable("saved_game", True), Load("saved_game"), SetVariable("saved_game", False), Jump("start") ] at main_eff1
If there is a "saved_game", it will load the "saved_game". If there isn't, it will start normally. I don't know if it's correct.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Giving two actions to an imagebutton

#9 Post by xela » Sat Feb 20, 2016 4:20 pm

Do you want the last save loading code? Try searching something along those lines in this forum section, I remember that it was discussed before.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]