kuroi wrote:
Perhaps it's not an issue at all and there are some very inventive ways to use the Transform function which would enable it to do everything that the ATL does or something like that.
Since it hasn't actually been mentioned yet: yes, you use the 'function' parameter of the Transform object to do pretty much all the cool functionality you can write in ATL statements.
If you want to have a thing which fades in over the course of the first second, and then moves to the right from xpos=200px to 400px over the course of the next second, you could write your transform function to look something like (off the top of my head) this:
Code: Select all
def myTransformFunction(tran, st, at):
if (st >= 0 and st <= 1):
tran.alpha = st
return 0
elif (st > 1 and st <= 2):
tran.xpos = 200 + ( (st - 1) * 200)
return 0
return 999999
myTransform = Transform(xpos=200, function=myTransformFunction)
which would be the equivalent of ATL like:
Code: Select all
transform myTransform:
xpos 200
alpha 0.0
linear 1 alpha 1.0
linear 1 xpos 400
If you want to do something 'on show', then do it when the at is 0.0; if you want to do something 'on replace', do it when the st is 0.0 and the at is not (presuming I remember which way around those two are); if you want to do something 'on hide', do it when 'hide_request' is True, and set hide_response to False until your thing has finished. Return 0 from your function if you're doing something you want to happen in a smooth manner.
PyTom wrote:Anything you can do with ATL, you can do with Transforms, using an appropriate Python function. This is 100% guaranteed, as ATL actually uses Transform internally to do its thing.
The problem here is that the documentation doesn't really make this particularly clear, and in fact includes statements like "There is no way to create ATL code programatically", which gives people the opposite impression. (I know it's not what you meant, but it's how a lot of people are likely to read it, IMO.)
Unless I'm missing something quite drastic, the
only way to do most of the cool stuff with Transform is by implementing your own transform functions, but the documentation doesn't really make it clear how to use that facility.
- When exactly will the transform's function will be called? Will it definitely be called with an st of 0 when the Displayable is first shown? Will it definitely be called when the Displayable is first hidden and have a chance to delay the hide? We presume that the answer to these questions must be 'yes' only if we've already been told that the Transform method can do everything ATL can, but the docs only say 'before the Transform is rendered', which doesn't even account for the 'hide' case at all.
- How does one then subsequently get their Transform hidden again? Is it just by setting hide_request to True and hide_response to True? Can one do this even if no hide statement or call to renpy.hide was made, to remove an item from the scene list?
How should one return from the transform function if the transform is effectively finished, if '0' makes it render again next frame? I used a very high number in the example above, but maybe -1 would be more appropriate? It doesn't say.
- How should the Transform's 'child' member be used? Is it possible to put another Transform in there and if so, what happens? I know the answers to these last two questions only because I was curious and tried it, but the correct answer isn't even implied in the docs for the second one of those.
If the answers to any of those questions are actually written in the docs, I didn't see them.
Something I still don't know about Transforms: when someone writes a complex ATL transform involving show and hide events and timed property modifications and so on, do you have a stock of plug-together functions that you construct and pass in, or do you do code generation to create a function on the fly which fulfils their requirements? I expect it's probably the latter, because after a bit of flexibility it possibly becomes the simpler thing to write, but if it's the former, is there any reason other people shouldn't use the same functions for their programmatically-generated Transforms?
And presuming you're using code generation or some other internal trick, it's still not really that plausible to programmatically-generate transforms, because you can't take parameters or user input or situational state and generate a transform that does cool ATL stuff dependent on that, because you have to write a function which does exactly what you want. (Well, you could get away with it by using a lot of generic methods and some currying, I expect, but that's a long way beyond most amateur programmers' abilities.)