[SOLVED] "Activating" Imagebutton functionality

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
doorknob22
Regular
Posts: 36
Joined: Wed Jul 22, 2020 8:43 am
Contact:

[SOLVED] "Activating" Imagebutton functionality

#1 Post by doorknob22 » Mon Nov 09, 2020 5:47 pm

Hi and thank you for reading this.

I'm trying to implement basic map functionality in my game. And have two questions:

1. If I remove the "Now What" text, the game breezes in and out of the code faster than my salary without showing the map or anything. How do I just show the map without using such pathetic tricks?
2. In order to get the hover functionality to work (on the "Yatz" image), I have to click on the map once. How can I display the map and have my buttons/territories hover-able without having to click the map?

Code: Select all

label maploop:
    show screen ingame_menu    
    "Now what?"

screen ingame_menu:
        imagebutton auto "map_%s.png" action Show("mapscreen") at top

screen mapscreen:
    imagebutton auto "Yatz_%s.png" action Show('hello_world') xpos 1460 ypos 490 focus_mask True
Last edited by doorknob22 on Wed Nov 11, 2020 6:42 pm, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: "Activating" Imagebutton functionality

#2 Post by hell_oh_world » Mon Nov 09, 2020 6:10 pm

Try adding modal True to your screen.

Code: Select all

screen mapscreen():
  modal True
  # your imagebuttons...

doorknob22
Regular
Posts: 36
Joined: Wed Jul 22, 2020 8:43 am
Contact:

Re: "Activating" Imagebutton functionality

#3 Post by doorknob22 » Mon Nov 09, 2020 6:20 pm

hell_oh_world wrote:
Mon Nov 09, 2020 6:10 pm
Try adding modal True to your screen.

Code: Select all

screen mapscreen():
  modal True
  # your imagebuttons...
I'm sorry but that didn't solve any of the problems I ran into.
1. If I remove the "Now what?" text, the code will run without displaying my map.
2. The hover functionality is still only activated after clicking the map.

Code: Select all

label maploop:
    show screen ingame_menu    
    "Now what?"

screen ingame_menu:
 
    imagebutton auto "map_%s.png" action Show("mapscreen") at top
    


screen mapscreen:
    modal True
    imagebutton auto "Yatz_%s.png" action Show('hello_world') xpos 1460 ypos 490 focus_mask True

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: "Activating" Imagebutton functionality

#4 Post by rayminator » Mon Nov 09, 2020 10:06 pm

use idle instead of auto

what version of renpy are you using?

stable version
prereleased version

if you want to have mouse move over that button to open without clicking

Code: Select all

screen button_overlay():
    mousearea:
        area (0, 0, 1.0, 100)
        hovered Show("buttons", transition=dissolve)
        unhovered Hide("buttons", transition=dissolve)

label start:
    show screen button_overlay

doorknob22
Regular
Posts: 36
Joined: Wed Jul 22, 2020 8:43 am
Contact:

Re: "Activating" Imagebutton functionality

#5 Post by doorknob22 » Tue Nov 10, 2020 1:22 pm

rayminator wrote:
Mon Nov 09, 2020 10:06 pm
use idle instead of auto

what version of renpy are you using?

stable version
prereleased version

if you want to have mouse move over that button to open without clicking

Code: Select all

screen button_overlay():
    mousearea:
        area (0, 0, 1.0, 100)
        hovered Show("buttons", transition=dissolve)
        unhovered Hide("buttons", transition=dissolve)

label start:
    show screen button_overlay
I'm using 7.3.5.606, stable recommended.

Can you elaborate what you meant by using "idle" instead of "auto"?

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: "Activating" Imagebutton functionality

#6 Post by rayminator » Tue Nov 10, 2020 2:21 pm

this part where it says auto

Code: Select all

imagebutton auto "map_%s.png" action Show("mapscreen") at top
to

Code: Select all

imagebutton idle "map_%s.png" action Show("mapscreen") at top

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: "Activating" Imagebutton functionality

#7 Post by Imperf3kt » Tue Nov 10, 2020 2:36 pm

I don't think this issue is related to idle/hover states.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
RicharDann
Veteran
Posts: 284
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: "Activating" Imagebutton functionality

#8 Post by RicharDann » Tue Nov 10, 2020 4:07 pm

doorknob22 wrote:
Mon Nov 09, 2020 6:20 pm
1. If I remove the "Now what?" text, the code will run without displaying my map.
How is your maploop label being run? If you're using a call statement, or the Call screen action, upon reaching the show screen statement, it may be returning to the previous label without showing the screen because there's no interaction afterwards (the game doesn't pause for the player to click or press a button). If you don't want to display some dialogue you can use pause statement.

Code: Select all

label maploop:
    show screen ingame_menu    
    pause
doorknob22 wrote:
Mon Nov 09, 2020 6:20 pm
2. The hover functionality is still only activated after clicking the map.
I didn't have this problem in my test project, setting modal to True in mapscreen works as expected. Unfortunately I'm not sure what may be causing the problem for you. Not sure if this is related, but bear in mind that if focus_mask is True, the hover will only activate when the mouse is over the actual colored pixels of the image.
The most important step is always the next one.

doorknob22
Regular
Posts: 36
Joined: Wed Jul 22, 2020 8:43 am
Contact:

Re: "Activating" Imagebutton functionality

#9 Post by doorknob22 » Tue Nov 10, 2020 4:57 pm

RicharDann wrote:
Tue Nov 10, 2020 4:07 pm
doorknob22 wrote:
Mon Nov 09, 2020 6:20 pm
1. If I remove the "Now what?" text, the code will run without displaying my map.
How is your maploop label being run? If you're using a call statement, or the Call screen action, upon reaching the show screen statement, it may be returning to the previous label without showing the screen because there's no interaction afterwards (the game doesn't pause for the player to click or press a button). If you don't want to display some dialogue you can use pause statement.

Code: Select all

label maploop:
    show screen ingame_menu    
    pause
doorknob22 wrote:
Mon Nov 09, 2020 6:20 pm
2. The hover functionality is still only activated after clicking the map.
I didn't have this problem in my test project, setting modal to True in mapscreen works as expected. Unfortunately I'm not sure what may be causing the problem for you. Not sure if this is related, but bear in mind that if focus_mask is True, the hover will only activate when the mouse is over the actual colored pixels of the image.
Yay! Replacing the silly "Now what?" statement with a pause solved the first issue. Thanks.

The only problem left is why the hover mechanism doesn't activate until I click at least once, anywhere on the map.

My code currently looks like this:

Code: Select all

label maploop:
    show screen ingame_menu    
    pause
    



screen ingame_menu:    
    imagebutton auto "map_%s.png" action Show("mapscreen") at top



screen mapscreen:
    $ iname = territoryList[0].name    
    imagebutton auto "Yatz_%s.png" action Show('hello_world',None,iname) xpos 1460 ypos 490 focus_mask True

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: "Activating" Imagebutton functionality

#10 Post by hell_oh_world » Tue Nov 10, 2020 10:36 pm

Do you mean that you want the mapscreen to appear when the imagebutton "map" is hovered in the ingame_menu screen?
There are various way you can execute an action through a button, refer to the docs https://www.renpy.org/dev-doc/html/scre ... magebutton.

Code: Select all

screen ingame_menu:    
    imagebutton auto "map_%s.png":
      action NullAction() # we provide an empty action as the main action so that we can hover the button, and once hovered the action below is executed.
      hovered Show("mapscreen")
      at top

doorknob22
Regular
Posts: 36
Joined: Wed Jul 22, 2020 8:43 am
Contact:

Re: "Activating" Imagebutton functionality

#11 Post by doorknob22 » Wed Nov 11, 2020 6:41 pm

Thank you everyone who helped, I figured it out.

My problem (button is not clickable and not bloody present) was due to the fact that I inserted it via

Code: Select all

imagebutton auto "map_%s.png" action Show("mapscreen") at top
, hence it depended on the Show("mapscreen") bit.

I changed my sad little code to this:

Code: Select all

label maploop:
    show screen ingame_menu    
    pause
    
screen ingame_menu:    
    #imagebutton auto "map_%s.png" action Show("mapscreen") at top #<- this makes the button dependent on the action 
    imagebutton auto "map_%s.png" action NullAction() # this says "just put the map here and move on"
    imagebutton auto "Yatz_%s.png" action Show('territory_screen') xpos 1460 ypos 490 focus_mask True
Again, thanks everyone who bothered to stop and help!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]