Check when transform is executing and when it's over?

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
Deji
Cheer Idol; Not Great at Secret Identities
Posts: 1592
Joined: Sat Oct 20, 2007 7:38 pm
Projects: http://bit.ly/2lieZsA
Organization: Sakevisual, Apple Cider, Mystery Parfait
Tumblr: DejiNyucu
Deviantart: DejiNyucu
Location: Chile
Contact:

Check when transform is executing and when it's over?

#1 Post by Deji »

Hi there!
I'm figuring out programming slowly (yay codecademy for its python course!) and of course I still have a ton to learn.
I figured this would be better done with a custom displayable class, but I still don't have the hang of them yet, so I'm using ATL instead...

Anyway, onto the question!

I have this:
Screenshot 2016-05-09 13.49.22.png
Clicking on the buttons moves the rectangle on the corresponding direction, 100 pixels at a time using linear and xpos/ypos.
Then it checks the position of the square to see if it's on a position for something to happen (I need to adjust this to not be so precise, but for now it works), then stuff happens and it returns to the moving loop.

My messy code is this (apologies for making eyes bleed with my messy code :'D ) :

Code: Select all

image mini_penny =  Solid("#F00", maximum=(100, 100))

screen move_gui:
    textbutton "Left" align (0.0,0.5)  action Return("left")
       
    textbutton "Right" align (1.0,0.5)  action Return("right")
       
    textbutton "Down" align (0.5, 1.0) action Return("down")

    textbutton "Up" align (0.5, 0.0) action Return("up")

transform at_center:
    xpos 300
    ypos 250

#I want things to move at 200 px/sec
default velocity = 0.005
default penny_xpos = 300
default penny_ypos = 250
default places = {
    "up":[300,50],
    "down":[400,450],
    "left":[0, 250],
    "right":[700, 250]
}
default done = ""

transform move_right(x):
    linear x*velocity xpos penny_xpos+x
transform move_down(y):
    linear y*velocity ypos penny_ypos+y
transform move_left(x):
    linear x*velocity xpos penny_xpos-x
transform move_up(y):
    linear y*velocity ypos penny_ypos-y

label move_test:
    $renpy.show("mini_penny", at_list=[at_center])

label check:
    show mini_penny
    python:
        for key in places:
            if places[key][0] == penny_xpos:
                if places[key][1] == penny_ypos:
                    renpy.call(key)
        else:
            renpy.call("move_loop")
    
label move_loop:
    
    call screen move_gui
    if _return == "left":
        $renpy.show("mini_penny", at_list=[move_left(100)])
        $penny_xpos -=100
        jump check
  
    elif _return == "right":
        $renpy.show("mini_penny", at_list=[move_right(100)])
        $penny_xpos +=100
        jump check
     
    elif _return == "up":
        $renpy.show("mini_penny", at_list=[move_up(100)])
        $penny_ypos -=100
        jump check
        
    elif _return == "down":
        $renpy.show("mini_penny", at_list=[move_down(100)])
        $penny_ypos +=100
        jump check
        
    jump move_loop

    
label right:
    "Arrived at right!"
    "Wooo! :D"
    "I should check the rest now." 
    $done = "right"
    return
label left:
    "Arrived at Left"
    "Wooo! :D"
    "I should check the rest now."
    $done = "left"
    return
label up:
    "Arrived at at up"
    "Wooo! :D"
    "I should check the rest now."
    $done = "up"
    return
label down:
    "Arrived at at down"
    "Wooo! :D"
    "I should check the rest now."
    $done = "down"
    return
Again, I figure this is way simpler to do with a class and methods, but, again, I'm still trying to decipher those ^^;
I actually had a function doing the checking of the position vs the places but it never worked, so I just put the whole thing on the check label instead =_=;

Now my questions:

1. I want the check to happen after the square is done moving, not after like it's happening now. How do I do this?

2. I want to know how to change the square to a different square WHILE the square is moving and back to the original square after it's done moving. How do I do this? (instinct says it should be something like an event? or checking the velocity of the object and if it's 0 or >0 do the things?)

Thanks in advance for any and all guidance you can give me *bows*
Image
Tumblr | Twitter
Forever busy :')
When drawing something, anything, USE REFERENCES!! Use your Google-fu!
Don't trust your memory, and don't blindly trust what others teach you either.
Research, observation, analysis, experimentation and practice are the key! (:

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Check when transform is executing and when it's over?

#2 Post by xela »

Deji wrote: 1. I want the check to happen after the square is done moving, not after like it's happening now. How do I do this?
Set a screen timer? Add a function to the transform function to execute right after linear movement to flip some variable? Write a UDD to have complete control of what's happening and when? Take you pick...
Deji wrote: 2. I want to know how to change the square to a different square WHILE the square is moving and back to the original square after it's done moving. How do I do this? (instinct says it should be something like an event? or checking the velocity of the object and if it's 0 or >0 do the things?)
I imagine you just change the child of the transform func... it's kinda weird that you've put this together without figuring out how to do that.
Like what we're doing? Support us at:
Image

User avatar
Deji
Cheer Idol; Not Great at Secret Identities
Posts: 1592
Joined: Sat Oct 20, 2007 7:38 pm
Projects: http://bit.ly/2lieZsA
Organization: Sakevisual, Apple Cider, Mystery Parfait
Tumblr: DejiNyucu
Deviantart: DejiNyucu
Location: Chile
Contact:

Re: Check when transform is executing and when it's over?

#3 Post by Deji »

xela wrote:
Deji wrote: 1. I want the check to happen after the square is done moving, not after like it's happening now. How do I do this?
Set a screen timer? Add a function to the transform function to execute right after linear movement to flip some variable? Write a UDD to have complete control of what's happening and when? Take you pick...
Deji wrote: 2. I want to know how to change the square to a different square WHILE the square is moving and back to the original square after it's done moving. How do I do this? (instinct says it should be something like an event? or checking the velocity of the object and if it's 0 or >0 do the things?)
I imagine you just change the child of the transform func... it's kinda weird that you've put this together without figuring out how to do that.
Hmmm.... the timer seems the most likely thing for me to use right now, since I know how it works, though the flipping variable would make the most sense.

I figure I'd want something like (warning: pseudocode!)

Code: Select all

char_moving = False

def move_char(child, img_idle, img_moving, direction, pixels):
   char_moving = True
   velocity = 0.025
   if direction == "l":
      show child_moving
      linear pixels*velocity xpos child.xpos-pixels
      show child_idle
    elif direction == "r":
       #etc
   char_moving = False

#then...
if (condition) and char_moving:
    #do stuff
...but in ren'py speak x'D

Any pointers about where to look at in the docs to manage this?
Image
Tumblr | Twitter
Forever busy :')
When drawing something, anything, USE REFERENCES!! Use your Google-fu!
Don't trust your memory, and don't blindly trust what others teach you either.
Research, observation, analysis, experimentation and practice are the key! (:

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Check when transform is executing and when it's over?

#4 Post by xela »

Deji wrote:(warning: pseudocode!)
No kidding :)

Weird puree made out of Ren'Py script and Python. I meant a simple transform func that toggles a variable on a scope you can access as one of (many possible) options, not whatever that func is supposed to do.

===>>
Possibly another way of checking if your animation is finished is to check if your atl_object.done is aliased to True.

===>>
One of the issues is that you're using a screen for this and as you say in your own post, this should be a UDD/Class... Screens are best used for interface, trying to figure out how to get them to jump through your hoops before understanding UDDs/ATL better might not be a good approach if you wish to get something complex going for your project.
Like what we're doing? Support us at:
Image

User avatar
Deji
Cheer Idol; Not Great at Secret Identities
Posts: 1592
Joined: Sat Oct 20, 2007 7:38 pm
Projects: http://bit.ly/2lieZsA
Organization: Sakevisual, Apple Cider, Mystery Parfait
Tumblr: DejiNyucu
Deviantart: DejiNyucu
Location: Chile
Contact:

Re: Check when transform is executing and when it's over?

#5 Post by Deji »

Yeah, I need to learn mode about UDDs, they still puzzle me ^^;
Image
Tumblr | Twitter
Forever busy :')
When drawing something, anything, USE REFERENCES!! Use your Google-fu!
Don't trust your memory, and don't blindly trust what others teach you either.
Research, observation, analysis, experimentation and practice are the key! (:

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Check when transform is executing and when it's over?

#6 Post by xela »

Deji wrote:Yeah, I need to learn mode about UDDs, they still puzzle me ^^;
It's a lot easier than it looks at first. Try showing an image using a UDD first, then animate a couple of images. You'll be recreating simple functionality, but you'll understand it a lot better. Toying with a UDD/ATL combo might also proof fruitful, followed by some basic geometry (you can find all the formulas online) and you'll know it well enough to do almost anything.

Anyway, I think this changes the displayable while it's moving and shown you a state of the atl object and it's written along the lines of your code:

Code: Select all

image mini_penny = Solid("#F00", maximum=(100, 100))

screen move_gui():
    textbutton "Left" align .0, .5  action Return("left")
    textbutton "Right" align 1.0, .5  action Return("right")
    textbutton "Down" align .5, 1.0 action Return("down")
    textbutton "Up" align .5, 0.0 action Return("up")

screen overlay():
    text "[meow.done]" align .5, .5
    timer .1 action renpy.restart_interaction repeat True
    
transform move_to(d, start_pos, end_pos, t=.5):
    d
    pos start_pos
    linear t pos end_pos
    "mini_penny"

label start:
    $ meow = move_to("mini_penny", (300, 250), (300, 250))
    show screen overlay
    show expression meow
    
label loop:
    call screen move_gui
    $ d, x, y = Solid("#%06x" % renpy.random.randint(0, 0xFFFFFF), xysize=(100, 100)), meow.xpos, meow.ypos
    if _return == "left":
       $ x = x - 100
    elif _return == "right":
        $ x = x + 100
    elif _return == "up":
        $ y = y - 100
    elif _return == "down":
        $ y = y + 100
    $ meow = move_to(d, (meow.xpos, meow.ypos), (x, y))
    show expression meow
    jump loop
Like what we're doing? Support us at:
Image

User avatar
Deji
Cheer Idol; Not Great at Secret Identities
Posts: 1592
Joined: Sat Oct 20, 2007 7:38 pm
Projects: http://bit.ly/2lieZsA
Organization: Sakevisual, Apple Cider, Mystery Parfait
Tumblr: DejiNyucu
Deviantart: DejiNyucu
Location: Chile
Contact:

Re: Check when transform is executing and when it's over?

#7 Post by Deji »

I started looking more into UDDs now. They still seem puzzling, but I will figure the out >O
Most of the examples I've seen from people seem huge and complicated, so I'll try to see if I can find simpler ones or figure out a simpler one and start from there :)

Thanks a lot for the piece of code! I'll give it a try :D
Image
Tumblr | Twitter
Forever busy :')
When drawing something, anything, USE REFERENCES!! Use your Google-fu!
Don't trust your memory, and don't blindly trust what others teach you either.
Research, observation, analysis, experimentation and practice are the key! (:

Post Reply

Who is online

Users browsing this forum: Google [Bot]