[Solved] How to trigger an event when player enters a screen?

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
Zenadillo
Newbie
Posts: 3
Joined: Thu Oct 15, 2020 2:55 pm
Contact:

[Solved] How to trigger an event when player enters a screen?

#1 Post by Zenadillo »

Hi, I'd just like to say that I'm very new to Ren'Py and the only way I've been able to learn has really been from select YouTube tutorials. I've been trying to use other resources but atm they feel a bit too advanced for me. I'm currently in a prototype stage of just trying to make a very basic point and click game.

With all that being said, how do I trigger a one-time dialogue event when the player enters a new screen for the first time? How do I set that kind of condition to be recognized?

Code: Select all

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        e "Dialogue"
I just learned how to active hotspots on imagemaps and I've learned the basics of image buttons. For what I've been trying, imagemaps have been easier for me to make for moving the player from one screen to another. However, putting dialogue along like this just results in an error. Same if I try to provide a label underneath.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens/myscreens.rpy", line 22: u'e' is not a keyword argument or valid child for the imagemap statement.
    e "Dialogue"
     ^

Ren'Py Version: Ren'Py 7.3.5.606
Thu Oct 15 15:29:58 2020
In addition, I'd like this to be a one-time event. I'm not very familiar with adding conditions to the situation, so if someone could help in that regard, I'd appreciate that as well. Thank you.
Last edited by Zenadillo on Sat Oct 17, 2020 3:32 am, edited 1 time in total.

anonymouse
Newbie
Posts: 23
Joined: Wed Oct 10, 2018 4:32 pm
Contact:

Re: How to trigger an event when player enters a screen?

#2 Post by anonymouse »

I haven't used imagemaps at all, but it seems like this should work?

Code: Select all

define first_time_toHallway = True

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        


label toHallway:

	if first_time_toHallway:
		e "Dialogue

		first_time_toHallway = False

	else:
		# something else?

User avatar
Oazu
Newbie
Posts: 11
Joined: Tue Aug 25, 2020 1:47 pm
itch: oazu
Location: USA
Contact:

Re: How to trigger an event when player enters a screen?

#3 Post by Oazu »

Zenadillo wrote: Thu Oct 15, 2020 3:34 pm Hi, I'd just like to say that I'm very new to Ren'Py and the only way I've been able to learn has really been from select YouTube tutorials. I've been trying to use other resources but atm they feel a bit too advanced for me. I'm currently in a prototype stage of just trying to make a very basic point and click game.

With all that being said, how do I trigger a one-time dialogue event when the player enters a new screen for the first time? How do I set that kind of condition to be recognized?

Code: Select all

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        e "Dialogue"
I just learned how to active hotspots on imagemaps and I've learned the basics of image buttons. For what I've been trying, imagemaps have been easier for me to make for moving the player from one screen to another. However, putting dialogue along like this just results in an error. Same if I try to provide a label underneath.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens/myscreens.rpy", line 22: u'e' is not a keyword argument or valid child for the imagemap statement.
    e "Dialogue"
     ^

Ren'Py Version: Ren'Py 7.3.5.606
Thu Oct 15 15:29:58 2020
In addition, I'd like this to be a one-time event. I'm not very familiar with adding conditions to the situation, so if someone could help in that regard, I'd appreciate that as well. Thank you.
I might be wrong OP but the 'e Dialogue' is being looked at by the imagemap because of spacing. It might work how you want if you have it like so?:

Code: Select all

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot(1187, 25, 456, 458) action Jump("toHallway")
    e "Dialogue!"
But I agree the if/else statement would look to see if it's the first time in the hallway and then play the event.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to trigger an event when player enters a screen?

#4 Post by Imperf3kt »

You can't use dialogue in a screen like that, you need to call a label or add a text element (which probably isn't what you're after)

Create a variable, add an if/else condition to the screen that checks said variable, if the variable is False, close the screen, set the variable to True, and jump to the label
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: How to trigger an event when player enters a screen?

#5 Post by nananame »

Since you're new to RenPy let me point out that there is no simple point and click game (a pun, get it? :D)

It requires using a lot of screens, jumping around in labels, ideally having a controller label which loads content... Don't get me wrong, it can be done by a beginner but it will be very hard because you don't know how RenPy works yet, and it wasn't really designed for point and clicks. My suggestion would be to start with a simple VN. You can play around with additional screens, perhaps put an object in some scenes, but just so you get a handle on the basics. When you understand screens and RenPy flow a bit more, then you can try the point and clicks.

That being said, the answer to your question would be to have a condition when you enter the label which calls that screen (best if it's a control label but for starters you may have a separate for each screen) and then run the even in script code. See? The answer is simple, but I don't know how your code is structured and how you control the flow.

Zenadillo
Newbie
Posts: 3
Joined: Thu Oct 15, 2020 2:55 pm
Contact:

Re: How to trigger an event when player enters a screen?

#6 Post by Zenadillo »

anonymouse wrote: Thu Oct 15, 2020 4:09 pm I haven't used imagemaps at all, but it seems like this should work?

Code: Select all

define first_time_toHallway = True

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        


label toHallway:

	if first_time_toHallway:
		e "Dialogue

		first_time_toHallway = False

	else:
		# something else?
So it seems I'm halfway there. However, I can't get it to change from the true statement to the false statement. If I just go with first_time_toHallway = False then I get an error.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 27: expected statement.
    first_time_toHallway = False
                         ^

Ren'Py Version: Ren'Py 7.3.5.606
Fri Oct 16 02:54:43 2020
If I use default first_time_toHallway it'll bring up the True condition only. If I use define first_time_toHallway then it'll have the false condition only. I've got everything else down, and appreciate all the help! I'm just struggling with this condition change, it seems.

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: How to trigger an event when player enters a screen?

#7 Post by nananame »

anonymouse wrote: Thu Oct 15, 2020 4:09 pm

Code: Select all

define first_time_toHallway = True

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        
label toHallway:

	if first_time_toHallway:
		e "Dialogue

		first_time_toHallway = False    <------this should be python

	else:
		# something else?
Playing with variable is python so you should either prefix the line with $ or make it python:
For one line it is simplest to prefix with $

Code: Select all

$first_time_toHallway = False
So it seems I'm halfway there. However, I can't get it to change from the true statement to the false statement. If I just go with first_time_toHallway = False then I get an error.

If I use default first_time_toHallway it'll bring up the True condition only. If I use define first_time_toHallway then it'll have the false condition only. I've got everything else down, and appreciate all the help! I'm just struggling with this condition change, it seems.
Don't use "define" for variables like this, use "default". Read the docs for the difference.

Python is used to modify variables.

anonymouse
Newbie
Posts: 23
Joined: Wed Oct 10, 2018 4:32 pm
Contact:

Re: How to trigger an event when player enters a screen?

#8 Post by anonymouse »

OP, sorry for the error in my test code! I just typed up something quick in notepad. Sounds like you're on your way, though. Did you find the online documentation? Apologizes if you did, but here's the link:

https://renpy.org/doc/html/

When I was first learning, I picked it up by reading the manual and browsing these forums. The cookbook forum is especially useful. There is a thread where PyTom lists some tutorials he made, and they are extremely useful if there is one that covers the task you're trying to do. Here's that thread.

viewtopic.php?f=51&t=47328

At the end of the day, you learn by doing, so you're on the right track.

EDITED: Nananame is correct about define vs default.
Variables that are defined using the define statement are treated as constant, are not saved or loaded, and should not be changed. (Ren'Py does not enforce this, but will produce undefined behavior when this is not the case.)
Sounds like everything will work fine while you are writing the game, but saving/loading won't work right for variables that change if you define them with 'define.' Use default instead. I learned something, too!

Zenadillo
Newbie
Posts: 3
Joined: Thu Oct 15, 2020 2:55 pm
Contact:

Re: How to trigger an event when player enters a screen?

#9 Post by Zenadillo »

nananame wrote: Fri Oct 16, 2020 7:18 am
anonymouse wrote: Thu Oct 15, 2020 4:09 pm

Code: Select all

define first_time_toHallway = True

screen Room2():
    imagemap:
        ground "Room2.png"
        hotspot (1187, 25, 456, 458) action Jump ("toHallway")
        
label toHallway:

	if first_time_toHallway:
		e "Dialogue

		first_time_toHallway = False    <------this should be python

	else:
		# something else?
Playing with variable is python so you should either prefix the line with $ or make it python:
For one line it is simplest to prefix with $

Code: Select all

$first_time_toHallway = False
So it seems I'm halfway there. However, I can't get it to change from the true statement to the false statement. If I just go with first_time_toHallway = False then I get an error.

If I use default first_time_toHallway it'll bring up the True condition only. If I use define first_time_toHallway then it'll have the false condition only. I've got everything else down, and appreciate all the help! I'm just struggling with this condition change, it seems.
Don't use "define" for variables like this, use "default". Read the docs for the difference.

Python is used to modify variables.
Thanks so much, I tried the $ to fix it, and it worked! I'll be sure to use default during that condition setup as well.

Post Reply

Who is online

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