Page 1 of 1

Can a python function create and return an ATL transform?

Posted: Sat Aug 20, 2016 6:20 pm
by Evildumdum
So i'm creating a tile based strategy game. each tile is marked by a waypoint (basically it's xpos and ypos). The path is a list of these waypoints that each unit moves between. Obviously there is a bit more to it than that, but that's the general overview.

Here's my problem:
I have a generator that determines all the possible routes a unit can take, records them and picks the most efficient route. However that route can have infinite changes of direction. Now usually i'd use a for loop to account for an infinite combination of N, S, E, W moves, but ATL doesn't accept for loops and it's like, nor can you alter variables passed to it in any meaningful way like you can in functions. This effectively limits your transforms to a pre-determined number of changes in direction since you can't put any type of generator in them.

Here's my question:
Is it possible to use a python function to instantiate an ATL transform and return it?

Re: Can a python function create and return an ATL transform

Posted: Sun Aug 21, 2016 8:54 am
by Iylae
I don't see why not, an ATL transform is a Class so once instantiated should be able to be returned as normal.

Re: Can a python function create and return an ATL transform

Posted: Sun Aug 21, 2016 9:11 am
by morganw
https://www.renpy.org/doc/html/atl.html
The Python equivalent of an ATL transform is the Transform() displayable. There is no way to create an ATL transform programmatically.
You can use a curried function as a Transform function, and pass values into that:
https://www.renpy.org/doc/html/trans_tr ... #Transform
https://github.com/renpy/renpy/issues/525

Re: Can a python function create and return an ATL transform

Posted: Sun Aug 21, 2016 10:32 am
by nyaatrap
It's not clear for me what you want to do exactly, but I'd share my knowledge.
This is not a well known thing, but transform IS pure python function itself. https://www.renpy.org/doc/html/trans_tr ... transforms
If you search defined objects in ren'py, you'll notice all transforms are just python functions.
So you can define transforms as python function. If you want to include ATL in a function, do something like:

Code: Select all

def sample_python_transform(displayable):
    new = transform_defined_in_atl(displayable)
    #do other things
    return new
Also, there's easier way to implement python function in ATL.

Code: Select all

init python:
    def func():
        #do something
        return x

transform test():
    xpos func() #it's execute the func then returns x when this transform is shown.
Though it may have trouble to control when to execute/update transform, I'm not sure before testing.

(Actually, there're more other ways to do things, but I don't know what's best for your code)

PS: and I wish ren'py supports for loop in both labels and transforms.