Issues Encountered in Implementing Conditional Hover Images for an Investigable Map

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
fgfg3356
Newbie
Posts: 15
Joined: Fri Jul 02, 2021 5:36 am
Contact:

Issues Encountered in Implementing Conditional Hover Images for an Investigable Map

#1 Post by fgfg3356 »

I've designed code for a screen in my game to create a map that allows for investigation.

For the imagemap, I set it up so that when day1_***_inspection = False, the HOVER image is "cleaning_site1_investigation". When it's TRUE, the image changes to "cleaning_site1_investigation2". The intention was to make it so that when a hotspot is clicked, it not only transitions to the respective investigation label but also changes the day1_***_inspection value to TRUE. This way, the next time the cursor hovers over that hotspot, the "cleaning_site1_investigation2" image appears. However, there's a problem.

The actions for IF day1_***_inspection: and the corresponding ELSE are working fine, but the imagemap does not update from "cleaning_site1_investigation" as it should—it remains unchanged. (I also recently noticed that only when all day1_***_inspection values are set to TRUE, then all the HOVER images switch to "cleaning_site1_investigation2".) I have tried changing the code's structure several times to solve this issue, but I haven't been able to resolve it with my current level of expertise. Please, I urgently need help.

Code: Select all

default day1_thick_pipe_ceiling_inspection = False
default day1_left_side_clutter_investigation = False
default day1_outside_investigation = False

# Function to count the number of times a site has been inspected

init python:
    day1_cleaning_site_inspection = 0

    def increment_inspection():
        global day1_cleaning_site_inspection
        day1_cleaning_site_inspection += 1


# Define functions to set each variable to True
init python:
    def set_day1_thick_pipe_ceiling_inspection_true():
        global day1_thick_pipe_ceiling_inspection
        day1_thick_pipe_ceiling_inspection = True

    def set_day1_left_side_clutter_investigation_true():
        global day1_left_side_clutter_investigation
        day1_left_side_clutter_investigation = True

    def set_day1_outside_investigation_true():
        global day1_outside_investigation
        day1_outside_investigation = True


screen cleaning_site_investigation_1():
    add "cleaning_site1"

    if dialogue_active:
        $ button_enabled = False
    else:
        $ button_enabled = True

    # Add background image. It is important to place it above 'use clues_menu' so that the buttons work on the background.
    if button_enabled and not zone_2:
        imagemap:
            ground "cleaning_site1"

            # Thick pipe
            if day1_thick_pipe_ceiling_inspection:
                hover "cleaning_site1_investigation2"
                hotspot (1129, 299, 621, 256) action NullAction()
            else:
                hover "cleaning_site1_investigation"
                hotspot (1129, 299, 621, 256) action [Function(increment_inspection), Function(set_day1_thick_pipe_ceiling_inspection_true), Jump("day1_thick_pipe_ceiling_inspection")]

            # Outside
            if day1_outside_investigation:
                hover "cleaning_site1_investigation2"
                hotspot (1473, 586, 321, 194) action NullAction()
            else:
                hover "cleaning_site1_investigation"
                hotspot (1473, 586, 321, 194) action [Function(increment_inspection), Function(set_day1_outside_investigation_true), Jump("day1_outside_investigation")]

            # Clutter on the left side
            if day1_left_side_clutter_investigation:
                hover "cleaning_site1_investigation2"
                hotspot (1009, 707, 438, 163) action NullAction()
            else:
                hover "cleaning_site1_investigation"
                hotspot (1009, 707, 438, 163) action [Function(increment_inspection), Function(set_day1_left_side_clutter_investigation_true), Jump("day1_left_side_clutter_investigation")]


User avatar
m_from_space
Eileen-Class Veteran
Posts: 1006
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Issues Encountered in Implementing Conditional Hover Images for an Investigable Map

#2 Post by m_from_space »

fgfg3356 wrote: Sat Jan 27, 2024 4:19 amPlease, I urgently need help.
The problem is simple: An imagemap can only ever have one "hover" image. But your code changes the hover image for each if-else-construct. The last one (clutter) decides on the hover image, since it's last executed. Not sure why Renpy doesn't raise an exception for you trying to use "hover" multiple times in an imagemap. Maybe because it's user-friendly. ;)

You simply cannot use one hover image for a hotspot, and another hover image for a different hotspot of the same imagemap. If you want different hovers, you have to use imagebuttons instead of an imagemap.

By the way, you do not have to call a function to just set something to True. Just use SetVariable("myvariable", True) inside a screen (including the quotes).

fgfg3356
Newbie
Posts: 15
Joined: Fri Jul 02, 2021 5:36 am
Contact:

Re: Issues Encountered in Implementing Conditional Hover Images for an Investigable Map

#3 Post by fgfg3356 »

m_from_space wrote: Sat Jan 27, 2024 10:22 am By the way, you do not have to call a function to just set something to True. Just use SetVariable("myvariable", True) inside a screen (including the quotes).
I apologize for the delay in my response.

I understand it might seem cumbersome, but I opted to use functions for a more straightforward organization of the code. I wanted to change the image for areas that have already been inspected, but it seems that's not feasible. I'll have to explore alternative approaches. Thank you for trying to assist me!

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot]