Ren'Py Imagebutton vs menu item - time specific dialogue option

Zenathos815

Newbie
Jul 26, 2017
53
23
Hey guys

So far dev stuff on my game has been going pretty well aside from a few details. I have been posting in the lemma soft thing and not getting responses and you guys have been more helpful so i am posting this one here to see if there is any suggestions


I have plans for specific times where during a time of day on certain days of the week a character is present at a certain location like say the MC is at home and is passing time but has a menu on screen with options like wait or sleep and they spend all day at that location for 3 days but lets say at night on Wednesday their roommate comes home and their "chibi" is displayed I would like the MC to have an option to start dialogue or start an event without having to disrupt the existing menu options.

I wanted to know if anyone has a good way of doing this that they can share. I tried adding a menu option but this seems impractical for scenes that may have multiple characters at one time on some days but not others and I was having an issue with the menu bugging where it would skip two time periods or would still show the character after the time period ended though the if statement specifically set to show them for that time and hide them otherwise. Might be an issue with how I structure it but I can't seem to figure it out and it seems complcated for those times with multiple characters.

I considered using imagebuttons so the player can click the character they want to talk to but I can't get the syntax right for some reason and the only guides that seem to give full examples are drected for menu options or fixed buttons.

I don't mind using an imagemap but if I can't figure out an imagebutton I imagine this would be much harder.

I would like to see how others have handled this because I imagine my code is trash and I'm curious to see what the most effective way to do this would be
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,101
14,746
If I understood correctly what you want, you should take a look at the code of :
-
-
What you looking for (the "click on a character for to talk to it") is inside. The second is probably the better option since it have really less code and so you should find what you search more easily. There's probably other games with the same mechanism, but I can't remember their names right now.

As for the menu, since they are way to rigid, I always thought that they should be reserved to the dialog. When you've the choice to few answer, it's good, you can even hide some of them if a condition isn't reached. But when it come to more choice, especially related to actions, imagebutton or even textbutton seem better to me. You can easily hide a lot of them with a single condition, have more than one list of buttons on the same screen, and so on.

And finally, imagebutton aren't this hard to use, but the official doc is made by the developer, so sometime hard to understand if you don't have yourself a good knowledge in programming. He tend to see a lot of things as obvious, which isn't the case ; sometimes I had to take a look directly at his code for to really understand this or that.
The minimal use is this :
Code:
 imagebutton:
     idle "images/my_buttons/this_button.png"
     action Return( 'thisButton' )
All you need, is the "this_button.png" picture. Obviously the action I used is just for the example, you can choose the one you want, or even add an alternate or hovered option.

A more elaborate use :
Code:
 imagebutton:
     idle "images/my_buttons/this_button.png"
     hover "images/my_buttons/this_button_cursor_over.png"
     action Return( 'thisButton' )
Here, you'll also need the "this_button_cursor_over.png" picture.
The first image will be seen anytime, except when the cursor is over the imagebutton. In this case, it's the second picture that will be shown.

And finally the "official" use:
Code:
 imagebutton:
     auto "images/my_buttons/this_button_%s.png"
     action Return( 'thisButton' )
Here, you need at least one image named "this_button_idle.png", that will be the equivalent of "this_button.png" on my two previous example.
Then you can also have an image named "this_button_hover.png", that will be the equivalent of "this_button_cursor_over.png" on my second example.
The intend of auto is to limit the code used. You define a common name ("this_button_") and an extension (".png") and ren'py do the rest, replacing "%s" by the actual state of the button.
So, if you want to have the button to be different when it's selected and the cursor is over it, you need to have a picture name "this_button_selected_hover.png".
The possible states (and so the possible values for "%s") are : insensitive, idle, hover, selected_idle and selected_hover.

Note that you have no obligation to have an image for every states. See auto as a meta code that will search which image "this_button_[one of the state].png" exist, and create the idle, hover, etc., line for you during the creation of the screen. This mean that, if a picture don't exist, then the related state will not have a specific picture.
By example, my second example have only defined a picture for two of the five states, and still work without problem. It will be the same if you use auto without all the picture defined. As long as the one for the idle state exist, all will be fine.

Hope it help. Sorry I'm a coder myself and not always good when it come to explain this kind of things ;)
 

Zenathos815

Newbie
Jul 26, 2017
53
23
If I understood correctly what you want, you should take a look at the code of :
-
-
What you looking for (the "click on a character for to talk to it") is inside. The second is probably the better option since it have really less code and so you should find what you search more easily. There's probably other games with the same mechanism, but I can't remember their names right now.

As for the menu, since they are way to rigid, I always thought that they should be reserved to the dialog. When you've the choice to few answer, it's good, you can even hide some of them if a condition isn't reached. But when it come to more choice, especially related to actions, imagebutton or even textbutton seem better to me. You can easily hide a lot of them with a single condition, have more than one list of buttons on the same screen, and so on.

And finally, imagebutton aren't this hard to use, but the official doc is made by the developer, so sometime hard to understand if you don't have yourself a good knowledge in programming. He tend to see a lot of things as obvious, which isn't the case ; sometimes I had to take a look directly at his code for to really understand this or that.
The minimal use is this :
Code:
 imagebutton:
     idle "images/my_buttons/this_button.png"
     action Return( 'thisButton' )
All you need, is the "this_button.png" picture. Obviously the action I used is just for the example, you can choose the one you want, or even add an alternate or hovered option.

A more elaborate use :
Code:
 imagebutton:
     idle "images/my_buttons/this_button.png"
     hover "images/my_buttons/this_button_cursor_over.png"
     action Return( 'thisButton' )
Here, you'll also need the "this_button_cursor_over.png" picture.
The first image will be seen anytime, except when the cursor is over the imagebutton. In this case, it's the second picture that will be shown.

And finally the "official" use:
Code:
 imagebutton:
     auto "images/my_buttons/this_button_%s.png"
     action Return( 'thisButton' )
Here, you need at least one image named "this_button_idle.png", that will be the equivalent of "this_button.png" on my two previous example.
Then you can also have an image named "this_button_hover.png", that will be the equivalent of "this_button_cursor_over.png" on my second example.
The intend of auto is to limit the code used. You define a common name ("this_button_") and an extension (".png") and ren'py do the rest, replacing "%s" by the actual state of the button.
So, if you want to have the button to be different when it's selected and the cursor is over it, you need to have a picture name "this_button_selected_hover.png".
The possible states (and so the possible values for "%s") are : insensitive, idle, hover, selected_idle and selected_hover.

Note that you have no obligation to have an image for every states. See auto as a meta code that will search which image "this_button_[one of the state].png" exist, and create the idle, hover, etc., line for you during the creation of the screen. This mean that, if a picture don't exist, then the related state will not have a specific picture.
By example, my second example have only defined a picture for two of the five states, and still work without problem. It will be the same if you use auto without all the picture defined. As long as the one for the idle state exist, all will be fine.

Hope it help. Sorry I'm a coder myself and not always good when it come to explain this kind of things ;)
So the other day when you gave your response I tried holiday island just to see what its like and that weirdness I described with the menu thing actually happens quite alot in that one, it doesn't advance time the way mine does but character images will disappear as you interact with them and things are triggered so its like the same but the opposite like the characters are changing state without time changing. Any who, I really appreciate the help on this one I am trying out yours right now to see how I like it Thanks a bunch!
 

Dheenz

New Member
Nov 16, 2017
14
4
me to stuck in imagebutton,,
see door no interaction..
i dont know what wrong
 

Dheenz

New Member
Nov 16, 2017
14
4
can gift code imagemaps sir..i want tuturial imagemap and imagebutton..
maybe next time can want tutorial "how player have money and invenstory"
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,101
14,746
me to stuck in imagebutton,,
see door no interaction..
i dont know what wrong
Er... I'm half asleep, but globally the screen seem correct to me. So, some guess...

First, the "scene" statement must be indented :
Code:
label start:
    scene house
Secondly I have a doubt, shouldn't it be a show instead ? So, try :
Code:
label start:
    show screen house
    "Control given back to the label"
Note that you can do the same test (the dialog line) with the "scene" version.

Is there really a label named "house" ?

What happen if you remove the pos (except the fact that the picture isn't at the right place) ?

What happen if you replace the Jump( "house" ) by a Return( "house" ) ? Try it like this
Code:
label start:
    call screen house
    if _return == "house":
        "Well, it worked"
    else:
        "I shouldn't even be here"

As for imagemap:
Code:
screen:
    imagemap:
        idle standardPicture.jpg
        hover highlightedPicture.jpg
        hotspot (820,230,200,400)  action Jump( "house" )
# (x,y, width, height) I've guessed width and height
You need two pictures, one which is the regular picture, and the other which have everything highlighted. To this, you add all the hotspot needed.

It works like this : Ren'py display the regular picture. When the mouse cursor is inside one of the area defined by a hotspot, it replace this area by the one in the highlighted picture. And if the player click in this area, then the related action is triggered.


Edit: hmm... Reading what I just wrote, shouldn't it even be "call screen" and neither "scene", nor "show screen" ? Try it...
Personal note: I really need to find time to sleep more :(
 

Dheenz

New Member
Nov 16, 2017
14
4
Er... I'm half asleep, but globally the screen seem correct to me. So, some guess...

First, the "scene" statement must be indented :
Code:
label start:
    scene house
Secondly I have a doubt, shouldn't it be a show instead ? So, try :
Code:
label start:
    show screen house
    "Control given back to the label"
Note that you can do the same test (the dialog line) with the "scene" version.

Is there really a label named "house" ?

What happen if you remove the pos (except the fact that the picture isn't at the right place) ?

What happen if you replace the Jump( "house" ) by a Return( "house" ) ? Try it like this
Code:
label start:
    call screen house
    if _return == "house":
        "Well, it worked"
    else:
        "I shouldn't even be here"

As for imagemap:
Code:
screen:
    imagemap:
        idle standardPicture.jpg
        hover highlightedPicture.jpg
        hotspot (820,230,200,400)  action Jump( "house" )
# (x,y, width, height) I've guessed width and height
You need two pictures, one which is the regular picture, and the other which have everything highlighted. To this, you add all the hotspot needed.

It works like this : Ren'py display the regular picture. When the mouse cursor is inside one of the area defined by a hotspot, it replace this area by the one in the highlighted picture. And if the player click in this area, then the related action is triggered.


Edit: hmm... Reading what I just wrote, shouldn't it even be "call screen" and neither "scene", nor "show screen" ? Try it...
Personal note: I really need to find time to sleep more :(
sankyu...i will try your suggestion ..