Page 1 of 1

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

Posted: Mon Jul 08, 2019 4:37 pm
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.

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

Posted: Mon Jul 08, 2019 5:36 pm
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.

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

Posted: Mon Jul 08, 2019 6:05 pm
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 :)