Can a python function create and return an ATL transform?

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
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Can a python function create and return an ATL transform?

#1 Post 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?
"If at first you don't succeed, try hitting it with a shoe."

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

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

#2 Post 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.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

morganw
Regular
Posts: 51
Joined: Fri Nov 20, 2015 7:00 pm
Contact:

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

#3 Post 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

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#4 Post 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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot]