[SOLVED] Call Screen, Imagebutton SetVariable - Not Working?

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
4listair
Newbie
Posts: 11
Joined: Tue Jul 31, 2018 10:54 pm
Contact:

[SOLVED] Call Screen, Imagebutton SetVariable - Not Working?

#1 Post by 4listair »

I'm trying to make a sort of tarot card reading thing where you can select different cards and then the card will "flip" over to show you what you got, but I can't seem to get it working.

In screens.rpy:

Code: Select all

screen reading():

    default tarot = 1

    add "images/bg_tarot.png"

    imagebutton:
        auto "images/card_small.png"
        xalign 0.315
        yalign 0.2
        action SetVariable("tarot", "1")
    imagebutton:
        auto "images/card_small.png"
        xalign 0.685
        yalign 0.2
        action SetVariable("tarot", "2")
    imagebutton:
        auto "images/card_small.png"
        xalign 0.5
        yalign 0.7
        action SetVariable("tarot", "3")
In script.rpy:

Code: Select all

    $ tarot = renpy.call_screen("reading")
    if tarot == 1:
        show card1:
            xalign 0.315
            yalign 0.2
        with dissolve

    if tarot == 2:
        show card2:
            xalign 0.685
            yalign 0.2
         with dissolve

    if tarot == 3:
        show card3:
            xalign 0.5
            yalign 0.7
        with dissolve
Last edited by 4listair on Thu Aug 16, 2018 5:26 pm, edited 1 time in total.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Call Screen, Imagebutton SetVariable - Not Working?

#2 Post by Kia »

what part is your problem? randomizing, animation or the click action?

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Call Screen, Imagebutton SetVariable - Not Working?

#3 Post by Alex »

Note

Code: Select all

action SetVariable("tarot", "1")
will set 'tarot' to text value '1', so the next check will fail

Code: Select all

if tarot == 1

Try

Code: Select all

action SetVariable("tarot", 1)

Note 2
When you 'call' a screen it must return a value. So instead of

Code: Select all

action SetVariable("tarot", 1)
try

Code: Select all

action Return(1)
https://www.renpy.org/doc/html/screen_a ... tml#Return

User avatar
dGameBoy101b
Regular
Posts: 31
Joined: Sun Aug 12, 2018 8:32 am
itch: dgameboy101b
Contact:

Re: Call Screen, Imagebutton SetVariable - Not Working?

#4 Post by dGameBoy101b »

Rather than calling the screen directly through python, you could use the renpy "call screen" function and then use the "_return" variable to read the returned value. Also you should use the "elif" conditional statement for the second and third tests to absolutely ensure that only one card is chosen at a time (even though, logically, no more than one of the conditions should be meet in a single instant).

Code: Select all

init:
    screen reading():
        add "images/bg_tarot.png"
        imagebutton:
            auto "images/card_small.png"
            xalign 0.315
            yalign 0.2
            action Return(1)
        imagebutton:
            auto "images/card_small.png"
            xalign 0.685
            yalign 0.2
            action Return(2)
        imagebutton:
            auto "images/card_small.png"
            xalign 0.5
            yalign 0.7
            action Return(3)
label start:
    call screen reading
    $ tarot = _return
    if tarot == 1:
        show card1:
            xalign 0.315
            yalign 0.2
        with dissolve
    elif tarot == 2:
        show card2:
            xalign 0.685
            yalign 0.2
         with dissolve
    elif tarot == 3:
        show card3:
            xalign 0.5
            yalign 0.7
        with dissolve

4listair
Newbie
Posts: 11
Joined: Tue Jul 31, 2018 10:54 pm
Contact:

Re: Call Screen, Imagebutton SetVariable - Not Working?

#5 Post by 4listair »

Thank you, everyone! The return script was what I needed. :")

Post Reply

Who is online

Users browsing this forum: No registered users