Screen Variable Changes When Clicking/Progressing [Solved]

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
floweringOrchid
Newbie
Posts: 14
Joined: Thu Oct 26, 2023 5:39 pm
Contact:

Screen Variable Changes When Clicking/Progressing [Solved]

#1 Post by floweringOrchid »

Hello! I have a screen that I'm using that grabs all the items in my list and presents them on screen like this:

Code: Select all

screen conclusion:
    vbox align (0.1, 0.5):
        spacing 100
        for e in list:
            textbutton "[e.n]" action SetVariable('selecting', False), Jump(e.label) at conclusion_float(0, 300, renpy.random.randint(-15, 0))
And this shows up fine! The issue is when the player clicks, progresses, any interaction, and the 'random int' number will reset and move everything on screen to a new point. What I'd like it to do is only choose the position when the screen is shown, not reset every time the player does something. Is there a way to do this? Or a way to set each textbutton point at a different position so they're not all in a straight box?

Here is the atl code that goes with it:

Code: Select all

    transform conclusion_float(x, y, t):
        subpixel True
        xpos(renpy.random.randint(x, y))
        on idle:
            pause t
            parallel:
                ease 3 yoffset 15
                ease 3 yoffset -15
                repeat

            parallel:
                ease 5 xoffset 30
                ease 5 xoffset -30
                repeat
Last edited by floweringOrchid on Thu Dec 07, 2023 1:10 pm, edited 1 time in total.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#2 Post by enaielei »

You can try storing the random int in the screen's parameter.

Code: Select all

screen conclusion(t=0):
   ...
   ...at conclusion_float(0, 300, t)

Code: Select all

label start:
    show screen conclusion(renpy.random.randint(-15, 0))
or in screen variables.

Code: Select all

screen conclusion():
   default t = renpy.random.randint(-15, 0)
   ...
   ...at conclusion_float(0, 300, t)

floweringOrchid
Newbie
Posts: 14
Joined: Thu Oct 26, 2023 5:39 pm
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#3 Post by floweringOrchid »

enaielei wrote: Sat Dec 02, 2023 12:24 am You can try storing the random int in the screen's parameter.

Code: Select all

screen conclusion(t=0):
   ...
   ...at conclusion_float(0, 300, t)

Code: Select all

label start:
    show screen conclusion(renpy.random.randint(-15, 0))
or in screen variables.

Code: Select all

screen conclusion():
   default t = renpy.random.randint(-15, 0)
   ...
   ...at conclusion_float(0, 300, t)
Thank you for the reply! Unfortunately, this still comes up with the issue of the random int changing when the player clicks/progresses. And storing it in a variable like t in a label or in a screen makes it singular, and all the buttons have the same movements style rather than each of them acting independently.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#4 Post by enaielei »

I see. I didn't notice that you were using a loop back there.
I experimented more on your code and came up with this.

Code: Select all

transform conclusion_float(x, y, t):
            subpixel True
            xpos(renpy.random.randint(x, y))
            pause t
            parallel:
                ease 3 yoffset 15
                ease 3 yoffset -15
                repeat

            parallel:
                ease 5 xoffset 30
                ease 5 xoffset -30
                repeat

screen conclusion:
    default rints = [renpy.random.randint(-15, 0) for _ in lst]
    vbox align (0.1, 0.5):
        spacing 100
        for i, e in enumerate(lst):
            textbutton "[e.n]" action SetVariable('selecting', False), Jump(e.label) at conclusion_float(0, 300, rints[i])
I removed the ATL event idle from your transform object. And then, in the screen, I pre-generated the random ints and assigned it to a screen variable rints.
Notice also that I'm using lst instead of list here. list is one of the reserved keywords in renpy.

floweringOrchid
Newbie
Posts: 14
Joined: Thu Oct 26, 2023 5:39 pm
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#5 Post by floweringOrchid »

enaielei wrote: Sat Dec 02, 2023 4:19 am I removed the ATL event idle from your transform object. And then, in the screen, I pre-generated the random ints and assigned it to a screen variable rints.
Notice also that I'm using lst instead of list here. list is one of the reserved keywords in renpy.
Apologies for the late reply! But thank you for the new code. I tried using it, and it still is giving me the same results. However, I think I'm just misunderstanding the lst vs list variable you're using, and I assume that's the issue and I'm not doing it correctly? I went through the links with them and my brain just isn't connecting with what I need to do with it ._.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#6 Post by enaielei »

I tried using it, and it still is giving me the same results
I tested it against textbutton clicks, so aside from the floating texts I have somewhere in the screen a textbutton that just prints something to the console. Clicking the button didn't reposition the floating texts.
Also, I tested it against the save screen. Right clicking to access the save screen then coming back to the floating texts didn't reset the positions as well.
I think I'm just misunderstanding the lst vs list variable you're using
lst is just an example name. Use whatever name you want for your variables except those that are included in the reserved keywords list.
In short, just rename your variables to something that doesn't violate the reserved keywords.

floweringOrchid
Newbie
Posts: 14
Joined: Thu Oct 26, 2023 5:39 pm
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#7 Post by floweringOrchid »

enaielei wrote: Wed Dec 06, 2023 7:05 pm lst is just an example name. Use whatever name you want for your variables except those that are included in the reserved keywords list.
In short, just rename your variables to something that doesn't violate the reserved keywords.
Ahh I definitely read that wrong then my bad! I'm not sure why I'm getting different results then :(

floweringOrchid
Newbie
Posts: 14
Joined: Thu Oct 26, 2023 5:39 pm
Contact:

Re: Screen Variable Changes When Clicking/Progressing

#8 Post by floweringOrchid »

Mkay after a little more fiddling, I removed the other random ints and that fixed it and it looks pretty much the same as I was going for with your code too. tysm for your help!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]