[Solved] "If statement" + adding imagebutton to a screen?

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
nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

[Solved] "If statement" + adding imagebutton to a screen?

#1 Post by nanashine »

In my game you can buy a cellphone or not.
If you don't buy the cellphone, nothing will show up.
If you buy it, it would show somewhere in your screen. And since it's usable, it would probably be an imagebutton.
Like:
Image

The problem is, what would the best way to do it?

I mean, there's a screen that is always showing in the game. That shows your points, etc.
I was thinking about adding the cellphone imagebutton to that screen.

I'm just confused on how to do it.

Like:
if cellphone = imagebutton phone

For example, let's just say it's the normal screen, without the phone:

Code: Select all

screen showingoptions:
        
    text "{size=30}[points]{/size}" xpos 18 ypos 80
    imagebutton auto "icons/seta_%s.png" pos(1200,230) action Jump("mainmp")
    imagebutton auto "icons/seta_%s.png" pos(1200,280) action Jump("store")
    imagebutton auto "icons/seta_%s.png" pos(1200,330) action Jump("chapters")
    imagebutton auto "icons/seta_%s.png" pos(1200,380) action Jump("seefriends")
This is the phone imagebutton:

Code: Select all

    imagebutton auto "icons/phone_%s.png" pos(1200,330) action Jump("cellphone")
And this is a random label:

Code: Select all

label park2:
    
    scene parkatnight
    show showingoptions
If you go to the store and buy the phone:

Code: Select all

    menu buyphone:
        
        "Buy cellphone.":
            ?
            
        "Don't buy cellphone":
            ?
How can I make the game "understand" that if you bought the phone, the imagebutton should be added to the screen?

Code: Select all

screen showingoptions:
        
    text "{size=30}[points]{/size}" xpos 18 ypos 80
    imagebutton auto "icons/seta_%s.png" pos(1200,230) action Jump("mainmp")
    imagebutton auto "icons/seta_%s.png" pos(1200,280) action Jump("store")
    imagebutton auto "icons/seta_%s.png" pos(1200,330) action Jump("chapters")
    imagebutton auto "icons/seta_%s.png" pos(1200,380) action Jump("seefriends")
    imagebutton auto "icons/phone_%s.png" pos(1200,330) action Jump("cellphone") ##### added imagebutton
It's something you can do at any time, that's why it's a little confusing.
The cellphone unlocks extra missions. You can play the whole game without it. It's optional.

Does anyone know how I could make this?

Thank you.
Last edited by nanashine on Mon Jul 08, 2019 6:06 pm, edited 1 time in total.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: "If statement" + adding imagebutton to a screen?

#2 Post by xavimat »

You can use "if" inside a screen. With a boolean variable it should be easy:

Code: Select all

default has_phone = False
screen somescreen():
    vbox:
        textbutton "Some button" action NullAction()
        if has_phone:  # <-- You can use "if" here.
            textbutton "Phone" action NullAction()
label start:
    show screen somescreen
    menu:
        "Buy phone?":
            $ has_phone = True
        "Don't buy":
            pass
    "If you have the phone, you'll see two buttons now."
You can even turn the variable to False again if in your story the player can sell, give away or lose the phone. And again to True if can be bought/found again.

EDIT:
A different problem is how you control the flow of your game. The action Jump("somelabel") will forget the point were the player was.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: "If statement" + adding imagebutton to a screen?

#3 Post by nanashine »

xavimat wrote: Mon Jul 08, 2019 5:36 pm You can use "if" inside a screen. With a boolean variable it should be easy:

Code: Select all

default has_phone = False
screen somescreen():
    vbox:
        textbutton "Some button" action NullAction()
        if has_phone:  # <-- You can use "if" here.
            textbutton "Phone" action NullAction()
label start:
    show screen somescreen
    menu:
        "Buy phone?":
            $ has_phone = True
        "Don't buy":
            pass
    "If you have the phone, you'll see two buttons now."
You can even turn the variable to False again if in your story the player can sell, give away or lose the phone. And again to True if can be bought/found again.

EDIT:
A different problem is how you control the flow of your game. The action Jump("somelabel") will forget the point were the player was.
Thank you so much! I had a doubt about using the "If" in this case.
I'll try it! Thanks :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot]