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.
The problem is that the "renpy.random.random" part only work once: after the first time it randomized it's dead set for every other loop. I want it to randomize anew whenever the animation repeats, but how can I do it?. I did found this thread but Dinova's function would not work with a linear ATL.
Thank for reading!
Last edited by Black Cat 2412 on Sun Mar 25, 2018 3:52 am, edited 3 times in total.
init:
python:
limit = renpy.random.randint(1, 5)
def custom_atl(trans, st, at):
# A function called inside the ATL block should receive these 3 arguments. More in the docs: https://www.renpy.org/doc/html/atl.html#function-statement
# Also, we should return the time in which this function will be called again. If None is returned, the control is passed to the next ATL statement.
global limit
if st > limit:
trans.alpha = 1.0
limit = renpy.random.randint(1, 5)
return None
trans.alpha = st/limit
return .01
image img:
"test.png"
alpha 0.05
function custom_atl # This is a custom linear
repeat
label start:
show img
"..."
jump start
Renpy's random module pushes values into the store, so they are available in saves/rollback etc.
You should be able to get a random that doesn't save by using Python's random module instead.
Remix wrote: ↑Thu Mar 22, 2018 2:59 pmYou should be able to get a random that doesn't save by using Python's random module instead.
I swear I tested this before working on my example.
It didn't work for some reason, then I just thought the block couldn't be modified once generated. Good to know it works.
init:
python:
limit = renpy.random.randint(1, 5)
def custom_atl(trans, st, at):
# A function called inside the ATL block should receive these 3 arguments. More in the docs: https://www.renpy.org/doc/html/atl.html#function-statement
# Also, we should return the time in which this function will be called again. If None is returned, the control is passed to the next ATL statement.
global limit
if st > limit:
trans.alpha = 1.0
limit = renpy.random.randint(1, 5)
return None
trans.alpha = st/limit
return .01
This works perfectly! Thank you so much!! ( I have no idea whatsoever about function-they seems so ailen to me : ( But I will look into it, since it seems to be very promising)
Remix wrote: ↑Thu Mar 22, 2018 2:59 pm
Renpy's random module pushes values into the store, so they are available in saves/rollback etc.
You should be able to get a random that doesn't save by using Python's random module instead.
Just remember to import the module first
Doing this does not work for me either, it just did not reset the random number no matter how many time I tried (I timed it so I'm absolutely sure)
A function is a block of code that will be executed every time you call it.
Honestly, this is a rather complex function to start with for people who never programmed before.
What you need to understand is that 'def' is a keyword that declares a function, the name in the right is the name of the function, what's inside the parentheses are arguments the function will work with, and everything inside the block above it are commands that do something with the arguments.
init python:
limit = renpy.random.randint(1, 5)
def custom_atl(trans, st, at):
global limit
if st > limit:
trans.alpha = 1.0
limit = renpy.random.randint(1, 5)
return None
trans.alpha = st/limit
return .01
# The image
image bg_1 light:
"bg 1 light.png"
alpha 0.5
function custom_atl
linear 2.0 alpha 0.5
repeat
In theory, it should loops seamlessly, but instead the image flickers (suddenly disappears for a noticeable fraction of a sec then reappears) whenever it repeats .
This problem does not happen if I use the traditional method:
Black Cat 2412 wrote: ↑Fri Mar 23, 2018 1:25 pm
Update: A problem pops up when I tried to make the animation loop
I'm sorry, this is my fault.
My math was wrong. I thought about a mathematical function that would give me y(0) = 0 and y(limit) = 1, but this is wrong. Since the initial value was 0.05 before, the flicker was there, but we couldn't notice. It was jumping from 0.05 to 0, and then going up to limit. When we jump from 0.5 to 0, the jump can now be seen. That's why it flickers. Now I believe I did the right math... I think this is the family of linear functions in which y(0) = 'start_alpha' and y(limit) = 1: st/limit * (1 - start_alpha) + start_alpha
init python:
limit = renpy.random.randint(1, 5)
start_alpha = 0.5 # You can change the start alpha in just one place now
def custom_atl(trans, st, at):
global limit, start_alpha
if st > limit:
trans.alpha = 1.0
limit = renpy.random.randint(1, 5)
return None
trans.alpha = st/limit * (1 - start_alpha) + start_alpha
return .01
image test:
"test.png"
alpha start_alpha
function custom_atl
linear 2.0 alpha start_alpha
repeat
label start:
show test
"..."
jump start
Anyway, the ATL was doing exactly what I told it to do. I just told it to do the wrong thing.