Need help with Renpy imagemap with variable string

Celaviegroup

Well-Known Member
Game Developer
Aug 27, 2018
1,246
3,121
Need help with Renpy


I want to make a main screen with both hover buttons and variable strings including episode, day, time etc.

The string I want to include is
def display_screen_header (version, text_color ="B"):
if text_color in ("B", "W"):
tcolor = text_color
else:
tcolor = "B"
if tcolor == "B":
tcolor = "#000"
else:
tcolor = "#fff"
if version in versions_list:
renpy.show ("Events",what=Text(" Events " + str(events) + " / " + str(events_list[versions_list.index(version)]), size=40, color=tcolor), at_list=[topleft])
renpy.show ("ep1",what=Text(" Episode " + str(episode), size=40, color=tcolor), at_list=[topleft])
renpy.show ("Daytime", what = Text(day_depending_of_hour() + " " + str(shrink_hour(hour)) + ":" + get_minutes_string(minutes) + " ", size = 40, color = tcolor), at_list=[topright])


As background image I use this:

screen main_background():
imagemap:
if hour <= 16:
idle "main_day"
hover "main_day_h"
$ display_screen_header (get_reached_version_id())
if hour >= 17 and hour <= 20:
idle "main_sunset"
hover "main_sunset_h"
if hour >= 22:
idle "main_night"
hover "main_night_h"

hotspot (1556, 743, 200, 45) action Jump("home")
hotspot (1368, 691, 165, 45) action Jump("garden")


I want to combine my screen main_background(): with string: $ display_screen_header (get_reached_version_id())

But it doesn’t work.
My string works on a static background and my imagemap works without my string or more correctly – it’s not shown at all.
I hope that someone can tell me what’s wrong
Thank you very much in advance
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,226
I want to combine my screen main_background(): with string: $ display_screen_header (get_reached_version_id())
Why don't you just use a text screen statement ? If you had did it, in place of calling your function, Ren'py would have thrown an exception telling you what is the problem ; text isn't a valid child of imagemap. Therefore you would have found the solution by yourself, you need to put the text somewhere else in the code of the screen.

Something like this should works :
Code:
screen main_background():
    imagemap:
        [...]
        hotspot (1368, 691, 165, 45) action Jump("garden")

    if hour <= 16 and get_reached_version_id() in versions_list:
        text ( "Events "+ str(events) + " / " + str(events_list[versions_list.index(get_reached_version_id())]) ):
            xpos 100   # In place of your leading spaces.
            ypos 100
            size 40
            color ( "#000" if text_color == "W" else "#FFF" )
    text ( "Episode " + str(episode) )
            xpos 100   # In place of your leading spaces.  
            ypos 140
            size 40
            color ( "#000" if text_color == "W" else "#FFF" )
    text ( day_depending_of_hour() + " " + str(shrink_hour(hour)) + ":" + get_minutes_string(minutes)  )
            xpos 0
            ypos 180
            size 40
            color ( "#000" if text_color == "W" else "#FFF" )
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
One issue you're likely to run into is that the main menu is loaded and displayed before the player either starts playing or loads a saved game.

I haven't looked at the whole of your post yet, but variables like hour strike me as the sort of things that would only have a realistic value AFTER the player has loaded their saved game.

You might want to look into .

Hopefully, it's something you've already got covered - I mention it only in case you haven't. Or perhaps you only want to alter the style of the main menu when the player goes to view the gallery or something... i.e. while actually already playing.

There was also a thread recently dealing with using variables to control screens. Where the end result was that variables altered which images appeared on the screen and which labels were jumped to. My reply there includes some example code. I don't think the same solution is needed for your problem, but it might give you some insights as to what might be possible.
 
  • Like
Reactions: Celaviegroup

Celaviegroup

Well-Known Member
Game Developer
Aug 27, 2018
1,246
3,121
One issue you're likely to run into is that the main menu is loaded and displayed before the player either starts playing or loads a saved game.

I haven't looked at the whole of your post yet, but variables like hour strike me as the sort of things that would only have a realistic value AFTER the player has loaded their saved game.

You might want to look into .

Hopefully, it's something you've already got covered - I mention it only in case you haven't. Or perhaps you only want to alter the style of the main menu when the player goes to view the gallery or something... i.e. while actually already playing.

There was also a thread recently dealing with using variables to control screens. Where the end result was that variables altered which images appeared on the screen and which labels were jumped to. My reply there includes some example code. I don't think the same solution is needed for your problem, but it might give you some insights as to what might be possible.
Thanks a lot - I appreciate it. The reason could be that my main screen hide the variables so I'll try to change it. Thanks anyhow