Screen with on off buttons

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
Kamos
Regular
Posts: 33
Joined: Mon Jan 02, 2017 5:18 am
Tumblr: Kamos
Contact:

Screen with on off buttons

#1 Post by Kamos »

Hello everyone. I have one little question....

I want to make simple screen with 7 Lamps.... When you click on lamp 1 lamp 1 start shine.... but only when you have light bulbs in your possesion.... then when you click on lampt 3 lamp 3 will shine if you have bulb and lamp 1 still shine if you dont turn it off before...

What is the best way to make that screen???

Thanks

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Screen with on off buttons

#2 Post by Imperf3kt »

Some simple conditionals and the very basic python is all you need.


Start by building a screen. I will assume you want it to take up the whole game screen. I also assume your game is 1280x720.
For simplicity, I will use a vpgrid.

Code: Select all

screen lamps():
    
    tag menu
    style_prefix "lamps_menu"
    add "my background.png"
        
    vpgrid:
        xmaximum 700
        xfill True
        xpos 0
        ypos 0
        cols 1
        spacing 20
        draggable False
Add your lamps and include a python variable.

Code: Select all

        if lamp == 0:
            add imagebutton idle "lamp_off.png" hover "lamp_off.png" focus_mask True action SetVariable(lamp, 1)
        else:
            add magebutton idle "lamp_on.png" hover "lamp_on.png" focus_mask True action SetVariable(lamp, 0)
Be aware that whilst using a vpgrid, all elements inside it are pre-sized to the first object. If you want to add other stuff, consider a vbox or some other screen element.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Kamos
Regular
Posts: 33
Joined: Mon Jan 02, 2017 5:18 am
Tumblr: Kamos
Contact:

Re: Screen with on off buttons

#3 Post by Kamos »

Thank you very much.. but what if i need only that imagebutton - lamp png is same size as screen but only lamp is on specific place with 'blank' background

Kamos
Regular
Posts: 33
Joined: Mon Jan 02, 2017 5:18 am
Tumblr: Kamos
Contact:

Re: Screen with on off buttons

#4 Post by Kamos »

affter some tries it still give me same result:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 39: end of line expected.
    add imagebutton idle "Jessie.png" hover "Jessie.png" focus_mask True action SetVariable(lamp, 1)
                                      ^

File "game/script.rpy", line 41: end of line expected.
    add magebutton idle "Jessie.png" hover "Jessie.png" focus_mask True action SetVariable(lamp, 0)
                                     ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
is there any possibiltieis with imagebuttons or imagemap?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Screen with on off buttons

#5 Post by Imperf3kt »

I forgot about the requirement to have a bulb in your posession.

I also made a typo.

Code: Select all

        else:
            add imagebutton idle "lamp_on.png" hover "lamp_on.png" focus_mask True action SetVariable(lamp, 0)
I left out the i in "imagebutton"


If you want the image as part of the game background, it might be better to use an imagemap, but can be done with either.

I'm afraid I have never tried to do this yet so can't offer further help. Everything I posted so far is just based on past experience with programming and what I could learn by reading the documentation.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Google [Bot]