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
kl3in
Newbie
Posts: 2
Joined: Thu Dec 07, 2017 8:21 am
Contact:

SetVariable not working?

#1 Post by kl3in »

Greetings. I'm sorry if this is a dumb question or if I'm even posting this one the right place but I couldn't find much information online.
I've been trying to control the alpha of individual characters in a string by a transform. Since I didn't know how to go about this, I created a bunch of Text displayables, one for each letter. I wanted an effect where once you hovered over a button (which had this kind of text), the transparency of each of the letters would change randomly

Here are the transforms:

Code: Select all

transform test_trans(time):
    choice:
        pause time alpha 1.0
    choice:
        pause time alpha 0.75
    choice:
        pause time alpha 0.5
    choice:
        pause time alpha 0.25
    choice:
        pause time alpha 0.0
    repeat
    ease time alpha 1.0

transform test_normal:
    alpha 1.0
At first I wanted to see if there existed something like this:

Code: Select all

screen hbox_text(string, act):
    button action act:
        hovered:
            hbox:
                for c in string:
                    text "[c]" at test_text(0.1):
                        style "navigation_button_text"
        unhovered:
            hbox:
                for c in string:
                    text "[c]" at test_normal:
                        style "navigation_button_text"
Obviously this won't work, so instead I tried something like this:

Code: Select all

screen hbox_text(string, act):
    default r = 0
    button unhovered SetScreenVariable("r", 0) hovered SetScreenVariable("i", 1) action act:
        hbox:
            if r==1:
                for c in string:
                    text "[c]" at test_text(0.1):
                        style "navigation_button_text"
            else:
                for c in string:
                    text "[c]" at test_normal:
                        style "navigation_button_text"
But this wasn't working at all either.
So I created 10 variables v0, v1, ..., v9 each for one of my buttons to see if atleast that worked.

Code: Select all

screen hbox_text(string, act, i):
    button unhovered SetVariable("i", 0) hovered SetVariable("i", 1) action act:
        hbox:
            if i==1:
                for c in string:
                    text "[c]" at test_text(0.1):
                        style "navigation_button_text"
            else:
                for c in string:
                    text "[c]" at test_normal:
                        style "navigation_button_text"
I noticed that if I put SetVariable("v0", 0) manually, it worked, but when it was SetVariable("i", 0), it didn't. Why is that? And as you can see, this is extremely ugly. Is there a more elegant way to go about this? I'm extremely new to this, so I may be a bit slow. Thanks in advance.

kl3in
Newbie
Posts: 2
Joined: Thu Dec 07, 2017 8:21 am
Contact:

Re: SetVariable not working?

#2 Post by kl3in »

Not possible?

Post Reply

Who is online

Users browsing this forum: Bing [Bot]