Changing variable in ATL

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
nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Changing variable in ATL

#1 Post by nananame » Thu Jun 27, 2019 1:04 pm

Say I have a very simple atl:

Code: Select all

image animation:
    "image1"
    pause variable
    "image2"
    pause variable
    repeat
And used quite simply:

Code: Select all

show animation
Now, how could I change the pause duration? Simply changing the variable (i.e. $variable = 1 or $variable = 0.1) doesn't work.
I tried using a function inside the atl but that too hasn't worked.

Should I somehow write this as a transform? And then have a function in that? How would I show it and use it?

Sorry, been a very long day so maybe I'm not thinking straight but basically I want to simply SHOW the animation, and then during the course of the script when the variable changes, the animation speed will change (since the pause duration will change).

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Changing variable in ATL

#2 Post by drKlauz » Thu Jun 27, 2019 2:24 pm

Plain hack, but works :D

Code: Select all

image testanim:
  xzoom 1
  'marker.png'
  pause 0.5
  xzoom -1
  'marker.png'
  pause 0.5
  linear 0.5 alpha 0.0
  linear 0.5 alpha 1.0
  repeat
  
init python:
  def set_anim_speed(anim_id,speed_mult=1.0):
    for img_id,img in renpy.display.image.images.items():
      if not isinstance(img_id,basestring):
        img_id=' '.join(img_id)
      if isinstance(img,renpy.atl.ATLTransformBase) and img_id==anim_id:
        for stmt in img.block.statements:
          if isinstance(stmt,renpy.atl.Interpolation):
            original_duration=getattr(stmt,'original_duration',stmt.duration)
            stmt.original_duration=original_duration
            stmt.duration=original_duration/speed_mult

label start:
  show testanim at truecenter
  'start'
  $set_anim_speed('testanim',2.0)
  'double speed'
  $set_anim_speed('testanim',1.0)
  'normal speed'
  $set_anim_speed('testanim',0.5)
  'half speed'
  return
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: Changing variable in ATL

#3 Post by nananame » Thu Jun 27, 2019 2:57 pm

First of all - thanks! This works.

I'm not quite sure about the whole code could you elaborate a bit? I see that we loop through all the images (won't this cause some issues with a lot of images?). Then I'm not sure about the

Code: Select all

not isinstance
line...couldn't we skip that?
And then we get to the atl image which corresponds to the image we want and the whole duration is changed - although I would still appreciate a more detailed explanation of each piece so I can understand it even better.


Okay now that that works I come to another problem - which can perhaps be solved if I understand this code a bit better. I use a conditional image to decide which atl to run. Meaning:

Code: Select all

image animation1:
    "image1"
    pause 0.5
    "image2"
    pause 0.5
    repeat


image animation2:
    "image3"
    pause 0.5
    "image4"
    pause 0.5


image animation = ConditionSwitch("variable == 1", "animation1", "variable == 2","animation2")
What happens is if I use the conditionswitch image

Code: Select all

$set_anim_speed('animation',2.0)
it won't work. I have to specify the animation1 or animation2 itself. I am guessing this is because in the function we searched the isinstance ATLTransformBase? So again, if you could elaborate a bit here that would be great!

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Changing variable in ATL

#4 Post by drKlauz » Thu Jun 27, 2019 3:14 pm

Obligatory disclaimer: it is hack, there are good chance some future version of RenPy will break it.

Image names stored as tuples by RenPy, so "if not isinstance" part convert image name into string. It would be better to convert supplied name to RenPy representation and then read dict. Just little oversight on my side.

This code does only one thing, it change duration of plain ATL blocks. It does not handle "parallel" and likely some other blocks. ConditionSwitch is also have different class and need special casing. As i said code is hacky, but it does what needed from it.

You can either improve this code by adding special cases. Or you can make custom displayable and supply premultiplied st/at to child image. Then i think any animation can be embedded in this "player" without caring for special cases.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Changing variable in ATL

#5 Post by Imperf3kt » Thu Jun 27, 2019 5:54 pm

I seem to recall this working, but I could be mixing it up with some other function.

Untested, likely contains errors.

Code: Select all

default tim = 0.5
image animation:
    "image1"
    pause tim
    "image2"
    pause tim
    repeat
    
    
screen animation_one(tim) :
    add animation
    
label start:
    $tim = 0.5
    show screen animation_one
    "test"
    return
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: Changing variable in ATL

#6 Post by nananame » Fri Jun 28, 2019 8:33 am

It's a good idea. However I need to pass the variable to the screen when showing it. Then subsequent changes to the variable have no effect unless I hide the screen and show it again passing the variable again - it appears to work then - but only for a short second before an error pops up saying that ATL appears to be in an infinite loop.

Good attempt though!

Post Reply

Who is online

Users browsing this forum: Google [Bot], TioNick