Page 1 of 1

How to build a counter function that increases in increments when called?

Posted: Wed Jul 22, 2020 1:26 pm
by hemspekilegur
Hi y'all!

I'm attempting to loop 15 frames on screen, my current workaround is to list every photo file individually like so:

Code: Select all

        
        $ time = 0.09
        image ser_animated:
            yalign 0.1 xalign 0.2

            block:
                "Ser/ser1.png"
                pause time
                "Ser/ser2.png"
                pause time
                "Ser/ser3.png"
                #and so on up to ser15.png
                pause time
                repeat
        show ser_animated with dissolve
However as you can see this is a lot of code that seems unnecessary. All I really would like like to do is to change the name of the frame file within the repeat block every time it runs and then have the number reset to 1 after it hits 15 (there are 15 frames numbered 1-15).
How I attempted to solve this problem was an python function that I called to update the number of the frame with in the ATL block like so (was unsuccessful):

Code: Select all


	python:
		time = 0.09
		counter = 0
		def counter_function( ):
			if (counter < 15):
				counter += 1
			else:
				counter = 0
				
	image ser_animated:
            yalign 0.1 xalign 0.2

            block:
            	counter_function( )
                "Ser/ser[counter].png"
                pause time
                repeat
                
       show ser_animated with dissolve
 
**Update:
I realized the python code need to be put at the beginning of the script as

Code: Select all

init python:
, and I wrote it in a function that I called in the ATL repeat. This didn't work but also didnt produce an error message. So Im getting closer I think.
//End of Update


This however shows a variety of error message depending on the exact way I write the code. I'm not particularly experienced with Python and renpy so it could be either or. It could also be how the ATL language interacts with everything. Perhaps there is a way to do this without Python?
All help and suggestions welcome!

Thank you in advance, I really appreciate you all taking the time to read this :)