Using random variables inside an ATL statement.

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
User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Using random variables inside an ATL statement.

#1 Post by NocturneLight »

For those of you experienced with Ren'Py, is it possible to generate a random variable at the beginning of an ATL's loop statement and use that to determine what transform to do? If so how do you do that?

If it's not possible, here's my second question: how would you make a function that, based on a random number, chooses from a set of ATL's an ATL to show the player?
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2401
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Using random variables inside an ATL statement.

#2 Post by Ocelot »

What is wrolg with using choice?

Code: Select all

transform random:
    choice 5:
        ease 2.0 truecenter
    choice 1.5:
        linear 1.0 left
    choice:
        linear 1.0 right
    repeat
< < insert Rick Cook quote here > >

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Using random variables inside an ATL statement.

#3 Post by Remix »

Or using an " at random_choice " type syntax in the show:

Code: Select all

image i1 = Image("images/331.png")

transform a:
    xpos 0
    linear 2.0 xpos 500

transform b:
    xpos 1200
    linear 2.0 xpos 500

label start:    
    show i1 at renpy.random.choice( [a,b] )
    "..."
If that (or Ocelot's suggestion) doesn't suit, perhaps elaborate why
Personally I like that as each show can use different possible choices.
Frameworks & Scriptlets:

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Using random variables inside an ATL statement.

#4 Post by NocturneLight »

The effect I had in mind was a glow effect. Certain spots on the text box need to glow. Neither of those ideas would work for my initial idea because it needs to randomly pick a number at the beginning of the ATL, and then depending on the chosen number, it needs to load up an initial image and subsequent images associated with the random number chosen that complete the glow effect in the chosen spot of the textbox.

That's what I'm specifically trying to do.

If that's not possible to do in the manner I described, I wonder if there's a mathy way of doing it.
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Using random variables inside an ATL statement.

#5 Post by Milkymalk »

If you only need one random number that doesn't need to be re-randomized during the ATL block, you can randomize it before and supply as an argument IIRC:

Code: Select all

transform myTransform(a):
   xpos a

label dostuff:
    $ randomnumber = renpy.random.random(200)
    show eileen at myTransform(randomnumber)
I'm not sure if you can use python code inside a transform, but it's worth a try. I can't check it for myself right now, sorry.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Using random variables inside an ATL statement.

#6 Post by NocturneLight »

Milkymalk wrote: Sun Feb 25, 2018 8:54 pm If you only need one random number that doesn't need to be re-randomized during the ATL block, you can randomize it before and supply as an argument IIRC:

Code: Select all

transform myTransform(a):
   xpos a

label dostuff:
    $ randomnumber = renpy.random.random(200)
    show eileen at myTransform(randomnumber)
I'm not sure if you can use python code inside a transform, but it's worth a try. I can't check it for myself right now, sorry.

It would need to be randomized more than once, so that wouldn't work.
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: Using random variables inside an ATL statement.

#7 Post by irredeemable »

Not sure exactly what you're trying to do, but you might look at the function statement. Here's an example that's uses the same random # for position and fadein/fadeout duration that changes on each ATL loop:

Code: Select all

init python:
    first_foo = True

    def foo_function(trans, st, at):
        global random_foo
        global first_foo
        
        if first_foo:                               # starting a new loop
            first_foo = False
            random_foo = renpy.random.randint(1, 5)
            trans.align = (random_foo / 10.0,) * 2  # random x/yalign 0.1 - 0.5

        if st < random_foo:                         # random duration 1s - 5s
            x = st / (random_foo/2.0)               # probably bad algorithm
            trans.alpha = abs(x - (2 * int(x)))     # but hey it works
            return 0                                # repeat function ASAP

        first_foo = True                            # fall through to here
        return None                                 # when duration reached

image foo = Text("Foo")

transform foo():
    function foo_function
    pause 1
    repeat

label start:
    show foo at foo
    "foo"
Last edited by irredeemable on Mon Feb 26, 2018 1:23 am, edited 1 time in total.

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Using random variables inside an ATL statement.

#8 Post by NocturneLight »

irredeemable wrote: Sun Feb 25, 2018 10:20 pm Not sure exactly what you're trying to do, but you might look at the function statement. Here's an example that's uses the same random # for position and fadein/fadeout duration:

Code: Select all

init python:
    first_foo = True

    def foo_function(trans, st, at):
        global random_foo
        global first_foo
        if first_foo:
            first_foo = False
            random_foo = renpy.random.randint(1, 5)
            trans.align = [random_foo / 10.0] * 2
        if st < random_foo:
            x = st / (random_foo/2.0)
            trans.alpha = abs(x - (2 * int(x)))
            return 0
        else:
            first_foo = True
            return None

image foo = Text("Foo")

transform foo():
    function foo_function
    pause 1
    repeat

label start:
    show foo at foo
    "foo"
That's actually very close to what I was intending. The only difference is that I'm trying to get the random positioning of the fonts to be isolated to the left and right sides of the text box in spots where there was text on the textbox GUI itself. I was also intending for the randomly appearing font to be glowing, but looking at your code, messing with the alpha may work too. I'll play with the code and see if I can't get it to do what I want.
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

Post Reply

Who is online

Users browsing this forum: No registered users