Ren'Py Using script variables in screens

MTY Games

Newbie
Game Developer
Jan 12, 2019
55
90
Hi again. More help needed with Renpy coding.

I'm designing a basic phone in Renpy which allows the player to view messages. A mini phone is displayed in the top right corner. When the player clicks on the phone, it centers and enlarges it. The player can then click on the home button to turn it on.

Code:
screen mobilesmall:

    imagebutton idle "gui/phone/phonemini.png" xpos 1820 ypos 20 action ShowMenu('mobile')

screen mobile:

    imagemap:
        idle "gui/phone/phonelarge.png" xalign 0.5 yalign 0.5

        hotspot (197, 840, 75, 74) action ToggleScreen('homescreen')

screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
Result:

phone.png

Works fine, nice and easy. Now what I want to be able to do is have a notification icon appear on the phone if there is a message waiting for the player to read. I would like to be able to set a variable in the script file, such as
Code:
 $ message = True
and have the phone show a notification on top of the homescreen.

I have no idea how to implement this, but I've tried simple things like:

Code:
screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
    if $ = True:
        add "gui/phone/notification.png" xpos 1174 ypos 768
I could obviously have a completely seperate screen for the notification and call for it within the script but I wanted to create something prettier and have it all contained in the screens file.

Any help is hugely appreciated.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,685
Code:
screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
    if $ = True:
        add "gui/phone/notification.png" xpos 1174 ypos 768

I think this would be the right way:
Code:
screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
        if message == True:
             add "gui/phone/notification.png" xpos 1174 ypos 768
 

MTY Games

Newbie
Game Developer
Jan 12, 2019
55
90
I've tried that also, but I get an exception: "NameError: name 'message' is not defined."
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,555
2,168
Now what I want to be able to do is have a notification icon appear on the phone if there is a message waiting for the player to read.
Sounds like you want a composite image, possibly using ConditionalSwitch.

The only reason it came to mind, because I was answering another post today which had a video that covered it.


Maybe watch Elaine's video and see if you could adapt any of what she's saying to do what you need.
(I'm imagining a composite image of the phone and your notification icon, where the notification icon image is conditional upon the variable you want to use).
I've never used composite images, but it sounds like what you're aiming at.

Though maybe it doesn't apply to how screens use images.
 

JTheoryGames

New Member
Jan 19, 2019
4
3
Just to note.. the $ symbol is to indicate that the line is python code. You should put all non-renpy code after the $. Eg: $ if message == False
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,090
14,731
You should put all non-renpy code after the $. Eg: $ if message == False
Except that your example is the worse possible one (with and, for screens only, ) this for two reasons :
  • Firstly if imply a bloc, so it can't be defined as a . You need to declare a bloc to use it as Python code.
  • Secondly, is a totally legit Ren'py statement, even in .
 

JTheoryGames

New Member
Jan 19, 2019
4
3
Except that your example is the worse possible one (with and, for screens only, ) this for two reasons :
  • Firstly if imply a bloc, so it can't be defined as a . You need to declare a bloc to use it as Python code.
  • Secondly, is a totally legit Ren'py statement, even in .
well i was just giving a crued example.. if you prefer:
$ dark = user.input("string")
scene bg 001
mc "hello"
python:
if dark == bob
light = jim
scene bg 002
note, indenting isnt working here, cbf figuring it out now
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,090
14,731
well i was just giving a crued example. if you prefer:
It's not a question of preference, and what I said wasn't a criticism.
If someone who don't knew about the inline Python capability try your example, he will think that you said bullshit. If someone who don't understand how inline Python works try to use it with if because he saw it in your example, he will pass hours trying to figure out why it's not working for him.

note, indenting isnt working here, cbf figuring it out now
[code]whatever you want[/code]
 

3zi0_V

New Member
Mar 13, 2023
3
0
Hi again. More help needed with Renpy coding.

I'm designing a basic phone in Renpy which allows the player to view messages. A mini phone is displayed in the top right corner. When the player clicks on the phone, it centers and enlarges it. The player can then click on the home button to turn it on.

Code:
screen mobilesmall:

    imagebutton idle "gui/phone/phonemini.png" xpos 1820 ypos 20 action ShowMenu('mobile')

screen mobile:

    imagemap:
        idle "gui/phone/phonelarge.png" xalign 0.5 yalign 0.5

        hotspot (197, 840, 75, 74) action ToggleScreen('homescreen')

screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
Result:

View attachment 225558

Works fine, nice and easy. Now what I want to be able to do is have a notification icon appear on the phone if there is a message waiting for the player to read. I would like to be able to set a variable in the script file, such as
Code:
 $ message = True
and have the phone show a notification on top of the homescreen.

I have no idea how to implement this, but I've tried simple things like:

Code:
screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
    if $ = True:
        add "gui/phone/notification.png" xpos 1174 ypos 768
I could obviously have a completely seperate screen for the notification and call for it within the script but I wanted to create something prettier and have it all contained in the screens file.

Any help is hugely appreciated.

Hi there!
I was just looking for the same thing to do for the game I am trying to build presently. Were you able to solve the issue
Hi again. More help needed with Renpy coding.

I'm designing a basic phone in Renpy which allows the player to view messages. A mini phone is displayed in the top right corner. When the player clicks on the phone, it centers and enlarges it. The player can then click on the home button to turn it on.

Code:
screen mobilesmall:

    imagebutton idle "gui/phone/phonemini.png" xpos 1820 ypos 20 action ShowMenu('mobile')

screen mobile:

    imagemap:
        idle "gui/phone/phonelarge.png" xalign 0.5 yalign 0.5

        hotspot (197, 840, 75, 74) action ToggleScreen('homescreen')

screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
Result:

View attachment 225558

Works fine, nice and easy. Now what I want to be able to do is have a notification icon appear on the phone if there is a message waiting for the player to read. I would like to be able to set a variable in the script file, such as
Code:
 $ message = True
and have the phone show a notification on top of the homescreen.

I have no idea how to implement this, but I've tried simple things like:

Code:
screen homescreen:

    imagemap:
        idle "gui/phone/homescreen.png" xalign 0.5 yalign 0.5
    if $ = True:
        add "gui/phone/notification.png" xpos 1174 ypos 768
I could obviously have a completely seperate screen for the notification and call for it within the script but I wanted to create something prettier and have it all contained in the screens file.

Any help is hugely appreciated.

Hi there!
I was just looking too add a mobile feature for the game I am trying to build presently. Were you able to solve the issue? If so, Is it possible for you to share the code for a working mobile feature? Would be really helpful, but if not, I understand. Thanks ! :)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,090
14,731
Were you able to solve the issue?
You are necroing a four years old thread, talking to someone who haven't logged in since two years, asking for an answer that is already on the thread.
 

3zi0_V

New Member
Mar 13, 2023
3
0
You are necroing a four years old thread, talking to someone who haven't logged in since two years, asking for an answer that is already on the thread.
Well, I am new to this site. And that is my first message. Still figuring out things here, but thank you for letting me know.