renply image on imagebutton

Cohibozz

Member
Aug 14, 2018
126
27
i've some imagebutton for navigation on my game:
Code:
screen navroom_u:
    tag navroom_u
    zorder 1
    vbox:
        xalign 1.0 yalign 0.0
        imagebutton:
           auto "mc_room_hm1_%s.png"
           action Call( "myroom_hm1" )
        imagebutton:
            auto "kitchen_room_hm1_%s.png"
            action Call( "livingroom" )
        imagebutton:
           auto "city_map_%s.png"
           action Call( "city_map" )
now i want place dinamically (with timeday check) some icon with the faces of character of my game ON the room where tey are.

the time check is not the problem, but how can i put image over the preview of the room or the map place to show where the char are at moment?
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Code:
if daynumber = 1 and daytime = 1:
     add "charactersimages/character_1.png" xpos 100 ypos 100
if daynumber = 1 and daytime = 2:
     add "charactersimages/character_2.png" xpos 100 ypos 100
Something like this I think.

Change "daynumber" for you day of the week variable and "daytime" for time of the day.
Put images of your characters on a folder and select the good xpos and ypos values to show near the location icon of your map.
 

Cohibozz

Member
Aug 14, 2018
126
27
i'm triyng to add some if condition for time/day show end eventually event change show:

Code:
screen city_map():
    zorder 0
    modal True
    add "city.png"
    if coffee_unlock:
        imagebutton auto "city_map_coffee_%s.png" xpos 610 ypos 510 focus_mask True action Call("coffe_shop")
    else:
        imagebutton idle "city_map_coffee_idle.png" xpos 610 ypos 510 hover "city_map_coffee_lock_hover.png" focus_mask True action NullAction()
    if school_unlock:
        imagebutton auto "city_map_school_%s.png" xpos 998 ypos 524 focus_mask True action Call("school")
        if 9 < time < 14 and ls_event_school == False and (todays != "Sun" and todays != "Sat"):
            add "charimg/ls_small_round.png" xpos 998 ypos 474
    else:
        imagebutton idle "city_map_school_idle.png" xpos 998 ypos 524 hover "city_map_school_lock_hover.png" focus_mask True action NullAction()
        if 9 < time < 14 and ls_event_school == False and (todays != "Sun" or todays != "Sat"):
            add "charimg/ls_small_round.png" xpos 998 ypos 474


    imagebutton auto "city_map_myhouse_%s.png" xpos 1230 ypos 222 focus_mask True action Call("myhome_hm1")
    if m_event == False:
        add "charimg/m_small_round.png" xpos 1230 ypos 172
    else:
        if m_event_end < time < m_event_start:
            add "charimg/m_small_round.png" xpos 1230 ypos 172
    if todays == "Sun" or todays == "Sat":
        if ls_event == False:
            add "charimg/ls_small_round.png" xpos 1280 ypos 172


    imagebutton auto "city_map_mansion_%s.png" xpos 421 ypos 353 focus_mask True action Call("themansion_hm2")
but there is something with my todays the not work good.

ls and m always showed on my house

ls go on school correctly but she go also on Sat and Sun!


todays is defined in my daytime screen and work good.

Code:
screen daytime:
    tag daytime
    zorder 1
    if time == 0:
        $day +=1
    $ todays = "Tue"
    $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    $ todays =  daynames[(day%7)]

    $ fasetime = ["Late Night", "Morning", "Afternoon", "Evening", "Night"]
    $ nowtime = (time + 2)
    $ nowfase = fasetime[(nowtime / 6)]
    hbox:
        xalign 0.0 yalign 0.0
        textbutton "[todays]":
            background "black"
            text_style "mytextbutton"
            action NullAction()

        textbutton "[time]:00 - [nowfase]":
            background "black"
            text_style "mytextbutton"
            action If( time < 23, SetVariable("time", time + 1), SetVariable("time", 0))

        textbutton " @ [whereim]":
            background "black"
            text_style "mytextbutton"
            action NullAction()

and initialized in my script.rpy

Code:
init:
    $time = 8
    $day = 0
    $todays = "Sun"
    $email = False
    $whereim =""
    $lsschool = True


    #variabili eventi da attivare
    $ls_event_school = False
    $ls_event = False
    $ls_event_start = -1
    $ls_event_end = 25

    $bs_event = False
    $bs_event_start = -1
    $bs_event_end = 25

    $m_event = False
    $m_event_start = -1
    $m_event_end = 25

    $u_event = False
    $u_event_start = -1
    $u_event_end = 25

    $c_event = False
    $c_event_start = -1
    $c_event_end = 25
 

Cohibozz

Member
Aug 14, 2018
126
27
the problem is that todays is a local variable for the screen daytime how can i make it global?

i don't understand why...time is global...todays not.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Well, first, I'm not an expert with that...

But now reviewing you code I have view that in "screen daytime" screen you have set "$ todays = "Tue" ", why? I think this is not necessary, you are setting "todays" variable to "Tue" value when you don't need this...you already set "todays" variable to "Sun" in "init" and then the days are passing, but with this in your code, every time you show "daytime" screen the variable "todays" is set to "Tue".

As I said, I'm not an expert.

If you need to check variables, go to renpy console (shift + o) and type variable name there.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
Relative of screen.
Not exactly. It's "relative to the left side of the containing area". So, in the code below, for the frame and the second text the xpos/ypos will be relative to the screen. But for the first text they will be relative to the frame.
Code:
screen myTest:
    frame:
        xpos 100 ypos 100
        xsize 500 ysize 500
        background Solid( "#0F0" )

        text "inside":
            xpos 10 ypos 400

    text "outside":
        xpos 10 ypos 400

i don't understand why...time is global...todays not.
I don't understand it either. I read and read again your code, and don't see a reason for it to be local ; especially since this notion don't really exist with Ren'py statements and Screen Language statements. They are implied to works with "store" as both global and local source.
Try to force it as part of the store by prefixing it, writing "store.todays" instead of just "todays".
 
  • Like
Reactions: Porcus Dev

Cohibozz

Member
Aug 14, 2018
126
27
Well, first, I'm not an expert with that...

But now reviewing you code I have view that in "screen daytime" screen you have set "$ todays = "Tue" ", why? I think this is not necessary, you are setting "todays" variable to "Tue" value when you don't need this...you already set "todays" variable to "Sun" in "init" and then the days are passing, but with this in your code, every time you show "daytime" screen the variable "todays" is set to "Tue".

As I said, I'm not an expert.

If you need to check variables, go to renpy console (shift + o) and type variable name there.
is not important, it's only to inizialize it
 

Cohibozz

Member
Aug 14, 2018
126
27
i've added $ store.todays = todays
but it seem do not work
i've tryied also
$ store.todays = daynames[(day%7)]

but no difference

it's possible theres something wrong on:
if 9 < time < 14 and ls_event_school == False and (todays != "Sun" and todays != "Sat"):
is seems that ignore the last and directly (todays != "Sun" and todays != "Sat")

i think the error is here..i'm not good in renpy
 

Cohibozz

Member
Aug 14, 2018
126
27
i've triyed to divide the condiction in single if statement and in this "orrible" way it works fine!

Code:
screen city_map():
    zorder 0
    modal True
    add "city.png"
    if coffee_unlock:
        imagebutton auto "city_map_coffee_%s.png" xpos 610 ypos 510 focus_mask True action Call("coffe_shop")
    else:
        imagebutton idle "city_map_coffee_idle.png" xpos 610 ypos 510 hover "city_map_coffee_lock_hover.png" focus_mask True action NullAction()
    if school_unlock:
        imagebutton auto "city_map_school_%s.png" xpos 998 ypos 524 focus_mask True action Call("school")
        if 9 < time < 14 and ls_event_school == False :
            if todays != "Sun":
                if todays != "Sat":
                    add "charimg/ls_small_round.png" xpos 998 ypos 474
    else:
        imagebutton idle "city_map_school_idle.png" xpos 998 ypos 524 hover "city_map_school_lock_hover.png" focus_mask True action NullAction()
        if 9 < time < 14 and ls_event_school == False :
            if todays != "Sun":
                if todays != "Sat":
                    add "charimg/ls_small_round.png" xpos 998 ypos 474


    imagebutton auto "city_map_myhouse_%s.png" xpos 1230 ypos 222 focus_mask True action Call("myhome_hm1")
    if m_event == False:
        add "charimg/m_small_round.png" xpos 1230 ypos 172
    else:
        if m_event_end < time < m_event_start:
            add "charimg/m_small_round.png" xpos 1230 ypos 172


    if todays == "Sun" or todays == "Sat":
        if ls_event == False:
            add "charimg/ls_small_round.png" xpos 1280 ypos 172
    else:
        if time < 10 :
            add "charimg/ls_small_round.png" xpos 1280 ypos 172
        if time > 13 :
            add "charimg/ls_small_round.png" xpos 1280 ypos 172
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Code:
if 9 < time < 14 and ls_event_school == False and (todays != "Sun" and todays != "Sat"):
Have you tried without parentheses?
Code:
if 9 < time < 14 and ls_event_school == False and todays != "Sun" and todays != "Sat":
 

Cohibozz

Member
Aug 14, 2018
126
27
Code:
if 9 < time < 14 and ls_event_school == False and (todays != "Sun" and todays != "Sat"):
Have you tried without parentheses?
Code:
if 9 < time < 14 and ls_event_school == False and todays != "Sun" and todays != "Sat":
yes..my first try was without..
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
yes..my first try was without..
I supose that between 9 and 14 is "Morning" so you can try this:

Code:
if fasetime == "Morning" and ls_event_school == False and todays != "Sun" and todays != "Sat":
 

Cohibozz

Member
Aug 14, 2018
126
27
yes but i want more flexibility.. in the morning the char have to go to bathroom, make breakfast and then go at school. :) if i find the problem i post it.. now work...is orrible to see...but no problem for now..
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
it's possible theres something wrong on:
if 9 < time < 14 and ls_event_school == False and (todays != "Sun" and todays != "Sat"):
is seems that ignore the last and directly (todays != "Sun" and todays != "Sat")
It's not normal, but also not the first time I see something being weird with multi conditional if. The optimization of conditions works this way : If there's a and and the left part is False, then the condition already failed, Python don't look further. For an or it's the opposite, if the left part is True, then the condition already past, and Python stop here.
This mean that... but first, the "how-to" deal with problems in conditions :

What should be tried is to isolate each condition to make clear for Python what is the left part, and what is the right one ; this for each and/or in the condition :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school == False ) ) and ( ( todays != "Sun" ) and ( todays != "Sat" ) ):
On a side note, parenthesis have the same meaning in coding than in math. They aren't always needed, but they always explicitly separate each part of the code. So, never hesitate to overuse them, sometimes it's what make the difference between a code that works, and one that should but don't.


Then if it still don't works, try to revert what you can. By example here you've the two "!=", so you can try :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school != True ) ) and ( not todays in [ "Sun", "Sat" ] ):
Note that I changed both the condition for "ls_event_school" and "todays", but it's better to change one, the other, then both.
Side note: You can use list for things like this. Not doing it is not enough to cause the problem. Doing it shouldn't be enough to correct it. But it's still better since it reduce many conditions to a single one.


If it still don't works, the next option it to change the order of the conditions, trying to keep optimization in mind. As I see it, the more likely to happen is that you are out of school time, then out of school days, then that everything is overwrote by a school event.
So :
Code:
if ( 9 < time < 14 ) and ( not todays in [ "Sun", "Sat" ] ) and ( ls_event_school == False ):
Speaking of this, she have school only between 10 and 13 (both included) ? Isn't it "<=" instead ?


Now that I said all this, here, the fact that it works when you split it in multi if seem to indicate that Python do a wrong optimization ; for it the left part is False when it should be True. More explicitly, my guess is that it failed to clearly identify the different parts of the condition. I don't know how it see it, but one of the possibility (which is wrong here) can be :
Code:
if ( 9 < time < 14 and ls_event_school ) == False and (todays != "Sun" and todays != "Sat"):
As human, you know what you meant when writing the condition, and it's wrote correctly. But Python is just a machine. It have complex algorithms to split lines, they works fine 99,99% of the times, but there's still the 0.01% when the said algorithms fail to understand you.

Then when you split, therefore simplify the condition, Python fall back to the right
Code:
if  ( 9 < time < 14 ) and ( ls_event_school == False ):
The line being now shorter, the algorithms fall back on their feet ; it's more logical that the "== False" is part of a second condition, than the result of a single condition like above.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
It's not normal, but also not the first time I see something being weird with multi conditional if. The optimization of conditions works this way : If there's a and and the left part is False, then the condition already failed, Python don't look further. For an or it's the opposite, if the left part is True, then the condition already past, and Python stop here.
This mean that... but first, the "how-to" deal with problems in conditions :

What should be tried is to isolate each condition to make clear for Python what is the left part, and what is the right one ; this for each and/or in the condition :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school == False ) ) and ( ( todays != "Sun" ) and ( todays != "Sat" ) ):
On a side note, parenthesis have the same meaning in coding than in math. They aren't always needed, but they always explicitly separate each part of the code. So, never hesitate to overuse them, sometimes it's what make the difference between a code that works, and one that should but don't.


Then if it still don't works, try to revert what you can. By example here you've the two "!=", so you can try :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school != True ) ) and ( not todays in [ "Sun", "Sat" ] ):
Note that I changed both the condition for "ls_event_school" and "todays", but it's better to change one, the other, then both.
Side note: You can use list for things like this. Not doing it is not enough to cause the problem. Doing it shouldn't be enough to correct it. But it's still better since it reduce many conditions to a single one.


If it still don't works, the next option it to change the order of the conditions, trying to keep optimization in mind. As I see it, the more likely to happen is that you are out of school time, then out of school days, then that everything is overwrote by a school event.
So :
Code:
if ( 9 < time < 14 ) and ( not todays in [ "Sun", "Sat" ] ) and ( ls_event_school == False ):
Speaking of this, she have school only between 10 and 13 (both included) ? Isn't it "<=" instead ?


Now that I said all this, here, the fact that it works when you split it in multi if seem to indicate that Python do a wrong optimization ; for it the left part is False when it should be True. More explicitly, my guess is that it failed to clearly identify the different parts of the condition. I don't know how it see it, but one of the possibility (which is wrong here) can be :
Code:
if ( 9 < time < 14 and ls_event_school ) == False and (todays != "Sun" and todays != "Sat"):
As human, you know what you meant when writing the condition, and it's wrote correctly. But Python is just a machine. It have complex algorithms to split lines, they works fine 99,99% of the times, but there's still the 0.01% when the said algorithms fail to understand you.

Then when you split, therefore simplify the condition, Python fall back to the right
Code:
if  ( 9 < time < 14 ) and ( ls_event_school == False ):
The line being now shorter, the algorithms fall back on their feet ; it's more logical that the "== False" is part of a second condition, than the result of a single condition like above.
Yeah! Here you have an expert explanation ;)
 

Cohibozz

Member
Aug 14, 2018
126
27
It's not normal, but also not the first time I see something being weird with multi conditional if. The optimization of conditions works this way : If there's a and and the left part is False, then the condition already failed, Python don't look further. For an or it's the opposite, if the left part is True, then the condition already past, and Python stop here.
This mean that... but first, the "how-to" deal with problems in conditions :

What should be tried is to isolate each condition to make clear for Python what is the left part, and what is the right one ; this for each and/or in the condition :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school == False ) ) and ( ( todays != "Sun" ) and ( todays != "Sat" ) ):
On a side note, parenthesis have the same meaning in coding than in math. They aren't always needed, but they always explicitly separate each part of the code. So, never hesitate to overuse them, sometimes it's what make the difference between a code that works, and one that should but don't.


Then if it still don't works, try to revert what you can. By example here you've the two "!=", so you can try :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school != True ) ) and ( not todays in [ "Sun", "Sat" ] ):
Note that I changed both the condition for "ls_event_school" and "todays", but it's better to change one, the other, then both.
Side note: You can use list for things like this. Not doing it is not enough to cause the problem. Doing it shouldn't be enough to correct it. But it's still better since it reduce many conditions to a single one.


If it still don't works, the next option it to change the order of the conditions, trying to keep optimization in mind. As I see it, the more likely to happen is that you are out of school time, then out of school days, then that everything is overwrote by a school event.
So :
Code:
if ( 9 < time < 14 ) and ( not todays in [ "Sun", "Sat" ] ) and ( ls_event_school == False ):
Speaking of this, she have school only between 10 and 13 (both included) ? Isn't it "<=" instead ?


Now that I said all this, here, the fact that it works when you split it in multi if seem to indicate that Python do a wrong optimization ; for it the left part is False when it should be True. More explicitly, my guess is that it failed to clearly identify the different parts of the condition. I don't know how it see it, but one of the possibility (which is wrong here) can be :
Code:
if ( 9 < time < 14 and ls_event_school ) == False and (todays != "Sun" and todays != "Sat"):
As human, you know what you meant when writing the condition, and it's wrote correctly. But Python is just a machine. It have complex algorithms to split lines, they works fine 99,99% of the times, but there's still the 0.01% when the said algorithms fail to understand you.

Then when you split, therefore simplify the condition, Python fall back to the right
Code:
if  ( 9 < time < 14 ) and ( ls_event_school == False ):
The line being now shorter, the algorithms fall back on their feet ; it's more logical that the "== False" is part of a second condition, than the result of a single condition like above.
ty mate! i've to try and see if i can give a better look at my code.