Simple imagebutton that changes a variable then disappears?

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
Chungfriend
Newbie
Posts: 7
Joined: Sat May 23, 2020 8:52 pm
Contact:

Simple imagebutton that changes a variable then disappears?

#1 Post by Chungfriend »

I'm trying to add hidden items to my VN that give you shortcuts or secrets if you spot and click them. Imagebutton seems to be the easiest way to do this but I can't get it to work. I don't want it to do anything fancy and my VN is just a VN, not a point and click adventure in any way other than these hidden items.

So by that I mean my normal script is like:

Code: Select all

scene 1 with dissolve
person "Blah blah blah"
scene 2 with dissolve
person "Eeeeee."
etc with just menus that change variables and jump around, nothing fancy.

I want these transparent .pngs to show up on screen at the same time as the scene change, then change a variable and disappear when clicked as if they were taken into the inventory. Maybe show a message saying you acquired it too but I think I can just do that using an if statement with the variable.

Code: Select all

scene tut1 #an environment without the shovel present

    screen tutorialshovel():		
        imagebutton:
            xalign 0.5
            yalign 0.5
            idle "tutshovel.png"
            hover "tutshovelhover.png"
            action $ hasshovel = 1

    
This seems extremely simple and I don't know why it doesn't work.

Also tried

Code: Select all

scene tut1

    screen tutorialshovel():
        imagebutton:
            xalign 0.5
            yalign 0.5
            idle "tutshovel.png"
            hover "tutshovelhover.png"
            action Hide(tutorialshovel)

    Show(tutorialshovel)
to focus on just the hiding part and that doesn't work either.

What am I doing wrong?

Thank you for any advice.

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

Re: Simple imagebutton that changes a variable then disappears?

#2 Post by Imperf3kt »

Try this

Code: Select all

default hasshovel = False


screen tutorialshovel():
    imagebutton:
        xalign 0.5
        yalign 0.5
        idle "tutshovel.png"
        hover "tutshovelhover.png"
        action [SetVariable("hasshovel", True), Hide("tutorialshovel") 


label start:
    show screen tutorialshovel
    "I have found a shovel" 
Last edited by Imperf3kt on Wed Jul 15, 2020 8:21 pm, edited 1 time in total.
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

Chungfriend
Newbie
Posts: 7
Joined: Sat May 23, 2020 8:52 pm
Contact:

Re: Simple imagebutton that changes a variable then disappears?

#3 Post by Chungfriend »

Imperf3kt wrote: Mon Jul 13, 2020 11:27 pm Try this

Code: Select all

default hasshovel = False


screen tutorialshovel():
    imagebutton:
        xalign 0.5
        yalign 0.5
        idle "tutshovel.png"
        hover "tutshovelhover.png"
        action [SetVariable("hasshovel", True), Hide("tutorialshovel") 


label start:
    show tutorialshovel
    "I have found a shovel" 
Thank you! It works in that the game launches, but the shovel doesn't actually show up. It just shows the generic renpy girl silhouette with "tutorialshovel" written on her.
Also, clicking the girl doesn't seem to do anything, it just advances the dialogue. Is there a way to make the dialogue not advance if you click on the shovel?

Code: Select all

label start:
    scene black with dissolve
    "Playing this game should be pretty intuitive in general but I will show you one thing."
    scene tut1 with dissolve

    default hasshovel = False


    screen tutorialshovel():
        imagebutton:
            xalign 0.5
            yalign 0.5
            idle "Intro/tutshovel.png"
            hover "Intro/tutshovelhover.png"
            action [SetVariable("hasshovel", True), Hide("tutorialshovel"), Notify("Success.")]


label start1:
    show tutorialshovel
    "I have found a shovel"
If you can help me get this working I will donate $5 to whatever kind of charity you want haha.

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

Re: Simple imagebutton that changes a variable then disappears?

#4 Post by Imperf3kt »

You need to place the screen outside the label "start", screens aren't part of the script, they should be ideally placed in screens.rpy
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

eath
Newbie
Posts: 10
Joined: Tue Jul 14, 2020 11:52 am
Contact:

Re: Simple imagebutton that changes a variable then disappears?

#5 Post by eath »

show tutorialshovel

should be

show screen tutorialshovel

Sorry I can't help with the rest. Maybe "modal True" in the screen definition would help.

Post Reply

Who is online

Users browsing this forum: Alex