How do I make clickable objects for if statement?

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
BlackRegulus
Newbie
Posts: 1
Joined: Sat Jul 25, 2015 9:32 pm
Contact:

How do I make clickable objects for if statement?

#1 Post by BlackRegulus »

I want to make a ball move across the screen. If it is clicked it results in "Good job" or if missed or not click "Try again."

show ball:
xalign -.5 yalign .5
linear 1 xalign 1.5 yalign 1

If clicked:
e Good job.
else:
e Try again.


I get ATL statement contains two expressions in a row.

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: How do I make clickable objects for if statement?

#2 Post by Alera »

I believe what you need to do to make this work is have the ball as an imagebutton and display it in a screen. (Please someone correct me if there is an easier way?)

This would look something like this:

Code: Select all

init-2:
    transform mov_ball:
        xpos -10 ypos -10
        linear 1.0 xpos 900 ypos 700
### ^^^ We need this code to create our own transform which will make the ball move

screen moving_ball:
    imagebutton:
        idle "ball.png"
        hover "ball.png" #We could have a different image for the ball on hover if we wanted
        at mov_ball #This is what makes it move
        action Jump("GoodJob") #We use this instead of an 'if' statement. It only reacts if the ball is clicked.

####Somewhere After the START Label####

label MovBall:    
    show screen moving_ball #We display the screen with the moving ball
    $ renpy.pause(delay=1.0, hard=True) #This is what waits for the ball to go across and makes something happen if we missed it.
    hide screen moving_ball 
    "You missed the ball. Try again."
    jump MovBall
    
label GoodJob:
    hide screen moving_ball
    "Good job!"
I added some comments but let me know if it's not clear and if you wanted more explanations.
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot]