Setting up a variable for a single Imagebutton

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
Seekeroflight
Newbie
Posts: 3
Joined: Tue Oct 29, 2019 5:26 pm
Contact:

Setting up a variable for a single Imagebutton

#1 Post by Seekeroflight » Tue Oct 29, 2019 5:39 pm

Hi, I'm new to Ren'Py and I'm trying with no success to disable an imagebutton after it did it's thing.
my screen has 3 imagebuttons, 2 of them can be activated only once and they will send the player to a specific label, after the label has ended the screen is shown again but the button pressed for that label needs to be deactivated, or better, it has to send a text message, while the third one needs to be always active. How do I do this? Thanks in advance :(

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Setting up a variable for a single Imagebutton

#2 Post by rayminator » Tue Oct 29, 2019 5:53 pm

here is a example

Code: Select all

define mapdoctor = False

or 

default mapdoctor = False

imagebutton idle im.Scale("images/doctor.jpg", 550, 250) hover im.Scale("images/doctor2.jpg", 550, 250) action [ Start("doctor"), SetVariable("mapdoctor", True) ]

Seekeroflight
Newbie
Posts: 3
Joined: Tue Oct 29, 2019 5:26 pm
Contact:

Re: Setting up a variable for a single Imagebutton

#3 Post by Seekeroflight » Tue Oct 29, 2019 6:12 pm

I did try that way before
The code now looks like this

Code: Select all

screen expNightKitchen():
    add "exploration/nightad.jpg"
    default kfirst = False
    imagebutton:
        idle "sprites/kitchen/kkarsprite.png"
        hover "sprites/kitchen/kkarhover.png" focus_mask True
        action [Jump("karaftdin"), SetVariable("kfirst", True)]
    imagebutton:
        idle "sprites/kitchen/knatsprite.png"
        hover "sprites/kitchen/knathover.png" focus_mask True
        action Jump("nataftdin")
    imagebutton:
        idle "sprites/kitchen/downkexit.png"
        hover "sprites/kitchen/downkexithover.png" focus_mask True
        action Show("expNightMainCorridor"), Hide("expNightKitchen")
I also tried to define the variable and the button it's still active

User avatar
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

Re: Setting up a variable for a single Imagebutton

#4 Post by deltadidirac » Tue Oct 29, 2019 6:38 pm

I try an example:

before define your variable:

Code: Select all

default buttonvalue = 0
build your screen:

Code: Select all

screen your_screen:
	add "your image bg"
	if buttonvalue ==0:
		imagebutton:
			idle "button1-idle"
			hover "button1-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos xxx
			ypos xxx
		imagebutton:
			idle "button2-idle"
			hover "button2-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos yyy
			ypos xxx
		imagebutton:
			idle "button3-idle"
			hover "button3-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos yyy
			ypos xxx
	elif buttonvalue ==1:
		imagebutton:
			idle "button1-idle"
			hover "button1-idle"
			action [Show ("popup")]
			xpos zzz
			ypos xxx
		imagebutton:
			idle "button2-idle"
			hover "button2-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos yyy
			ypos xxx
		imagebutton:
			idle "button3-idle"
			hover "button3-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos yyy
			ypos xxx
	else:
		imagebutton:
			idle "button1-idle"
			hover "button1-idle"
			action [Show ("popup")]
			xpos zzz
			ypos xxx
		imagebutton:
			idle "button2-idle"
			hover "button2-hover"
			action [Show ("popup")]
			xpos yyy
			ypos xxx
		imagebutton:
			idle "button3-idle"
			hover "button3-hover"
			action [Hide ("your_screen"), Jump ("your_label")]
			xpos yyy
			ypos xxx
build the popup screen:

Code: Select all

screen your_popup:
	vbox:
		xpos xxx ypos xxx
		textbutton "here write your warning text about your buttons" action Hide ("popup")

build your label:

Code: Select all

label your_label:
	if buttovalue ==0:
		scene your_bg
		".........."
		$ buttonvalue +=1
		show screen your_screen
	elif buttonvalue ==1:
		scene your_bg
		"..... ------- "
		$ buttonvalue +=1
		show screen your_screen
	else:
		scene your bg2
		"........"
		show screen your_screen
show screen your_screen
perhaps all this could give you some ideas

Seekeroflight
Newbie
Posts: 3
Joined: Tue Oct 29, 2019 5:26 pm
Contact:

Re: Setting up a variable for a single Imagebutton

#5 Post by Seekeroflight » Wed Oct 30, 2019 11:23 am

Ok I finally managed. :roll:

Code: Select all

default buttonv = 0
default buttonb = False
The screen.

Code: Select all

screen myscreen():
    add "image.jpg"
    if buttonv ==0:
        imagebutton:
            idle "picture1.png"
            hover "picture1hover.png" focus_mask True
            action Jump("label1")
        imagebutton:
            idle "picture2.png"
            hover "picture2hover.png" focus_mask True
            action Jump("label2")
        imagebutton:
            idle "leave.png"
            hover "leavehover.png" focus_mask True
            action Show("screen2"), Hide("myscreen")
    if buttonv ==1 and buttonb == False:
        imagebutton:
            idle "picture1.png"
            hover "picture1hover.png" focus_mask True
        imagebutton:
            idle "picture2.png"
            hover "picture2hover.png" focus_mask True
            action Jump("label2")
        imagebutton:
            idle "leave.png"
            hover "leavehover.png" focus_mask True
            action Show("screen2"), Hide("myscreen")
    elif buttonv ==1 and buttonb == True:
        imagebutton:
            idle "picture1.png"
            hover "picture1hover.png" focus_mask True
            action Jump("label1")
        imagebutton:
            idle "picture2.png"
            hover "picture2hover.png" focus_mask True
        imagebutton:
            idle "leave.png"
            hover "leavehover.png" focus_mask True
            action Show("screen2"), Hide("myscreen")
    else:
        imagebutton:
            idle "picture1.png"
            hover "picture1hover.png" focus_mask True
        imagebutton:
            idle "picture2.png"
            hover "picture2hover.png" focus_mask True
        imagebutton:
            idle "leave.png"
            hover "leavehover.png" focus_mask True
            action Show("screen2"), Hide("myscreen")
And 2 separate labels.

Code: Select all

label label1:
    "....text...."
    window hide
    $ buttonv += 1
    call screen myscreen
    $ renpy.pause(hard=True)

label label2:
    "....text...."
    window hide
    $ buttonv += 1
    $ buttonb = True
    call screen myscreen
    $ renpy.pause(hard=True)
That way the player can decide which one to execute first.
Thanks all for the help :D

Post Reply

Who is online

Users browsing this forum: Ocelot