Ren'Py I come back again to want to ask you about renpy.

h0932377128

New Member
Sep 25, 2019
13
3
Hi guys. I once posted a question about renpy code and thanked everyone for the help. I did feel a little better about renpy. But this time I have a slightly harder question. Code to write an event, it only happens once. I mean when the "point statement" reaches a certain limit. Will open the event, or scene. For example, my point statement is 50 with John. When I entered John's room. It will show the scene. After that, all activities in John's room were back to normal. Something like "event display on first time label call only"

Here is my code. I tried this code but got the error "$ seen_tutorial is not define" And I defined "seen_tutorial" then I got "Possible infinite loop".

Code:
          $ seen_johnpoints1 = False 

  label johnroom:
           if john_points >= 20:
                   jump to johnpoints1
           scene johnpoints 
           with dissolve
           if time_points in [6,7,8,9,10,11,12]:
                       jump morning
           if time_points in [13,14,15,16,17]:
                       jump afternoon
           if time_points in [18,19,20,21,22]:
                       jump evening
           menu:
                      "Call john":
                                jump john1
                      "Do something":
                                jump john2
                      "Go out":
                                jump hallway
   label johnpoints1:
           if seen_johnpoints1:
                    jump johnroom
           $ seen_johnpoints1 = True
           scene j1
           with dissolve
           pause 1
           scene j2
           with dissolve
           pause 1
           ........     
           jump johnroom

      ---------------> It becomes infinite. I think I saw that scene, I guess returning to the label is possible. Why "infinite loop"?

I tried another code

Code:
          $ seen_johnpoints1 = False 

  label johnroom:
           if john_points >= 20:
                   jump to johnpoints1
           scene johnpoints 
           with dissolve
           if time_points in [6,7,8,9,10,11,12]:
                       jump morning
           if time_points in [13,14,15,16,17]:
                       jump afternoon
           if time_points in [18,19,20,21,22]:
                       jump evening
           menu:
                      "Call john":
                                jump john1
                      "Do something":
                                jump john2
                      "Go out":
                                jump hallway
   label johnpoints1:
           if johnpoints1.is_seen(ever=False):     
                     jump after_tutorial 
           scene j1
           with dissolve
           pause 1
           scene j2
           with dissolve
           pause 1
           ........     
           jump johnroom

      ---------------> But the label johnpoints1 repeats a circle with no exit.




Hope everyone can help me. Thank you
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Maybe adding a variable to see if you've "seen" the label "johnpoints1".
The variable "johnpoints1_done" will be "False". When "john_points" is equal or greater than 20 they will jump to the label "johnpoints1", but at the end of that label the variable "johnpoints1_done" will change to "True", this way it will no longer be possible to jump back to the same label.

NOTE: I don't know in what mode, or when, you increase the points of the variable "john_points".

Code:
default johnpoints1_done = False
default john_points = 0

  label johnroom:
           if john_points >= 20 and johnpoints1_done == False:
                   jump to johnpoints1
           scene johnpoints  with dissolve
           if time_points in [6,7,8,9,10,11,12]:
                       jump morning
           if time_points in [13,14,15,16,17]:
                       jump afternoon
           if time_points in [18,19,20,21,22]:
                       jump evening
           menu:
                      "Call john":
                                jump john1
                      "Do something":
                                jump john2
                      "Go out":
                                jump hallway
   label johnpoints1:
           scene j1
           with dissolve
           pause 1
           scene j2
           with dissolve
           pause 1
           ........
           $ johnpoints1_done = True    
           jump johnroom
 
Last edited:

h0932377128

New Member
Sep 25, 2019
13
3
Maybe adding a variable to see if you've "seen" the label "johnpoints1".
The variable "johnpoints1_done" will be "False". When "john_points" is equal or greater than 20 they will jump to the label "johnpoints1", but at the end of that label the variable "johnpoints1_done" will change to "True", this way it will no longer be possible to jump back to the same label.

NOTE: I don't know in what mode, or when, you increase the points of the variable "john_points".

Code:
default johnpoints1_done = False
default john_points = 0

  label johnroom:
           if john_points >= 20 and johnpoints1_done == False:
                   jump to johnpoints1
           scene johnpoints  with dissolve
           if time_points in [6,7,8,9,10,11,12]:
                       jump morning
           if time_points in [13,14,15,16,17]:
                       jump afternoon
           if time_points in [18,19,20,21,22]:
                       jump evening
           menu:
                      "Call john":
                                jump john1
                      "Do something":
                                jump john2
                      "Go out":
                                jump hallway
   label johnpoints1:
           scene j1
           with dissolve
           pause 1
           scene j2
           with dissolve
           pause 1
           ........
           $ johnpoints1_done = True   
           jump johnroom
i will try this. Thank you very much
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,967
16,217
---------------> It becomes infinite. I think I saw that scene, I guess returning to the label is possible. Why "infinite loop"?
To go further than what mgomez0077 said, you've the infinite loop because of this :
  • Oh, the points are good, lets visit johnpoints1 ;
  • Display of the scene ;
  • Alright, time to return to johnroom ;
  • Oh, the points are good, lets visit johnpoints1 ;
  • Oh, we already did this, we return to johnroom ;
  • Oh, the points are good, lets visit johnpoints1 ;
  • Oh, we already did this, we return to johnroom ;
    [...]
  • Oh, the points are good, lets visit johnpoints1 ;
  • Oh, we already did this, we return to johnroom ;

Therefore, like he said, perform the "have the player already been here" test before you jump, and there's no more infinite loop.



Or alternatively you can instead of jump :
Python:
  label johnroom:
           if john_points >= 20:
                   call johnpoints1
           scene johnpoints 
           with dissolve
   [...]
   label johnpoints1:
           if seen_johnpoints1:
                    return
           $ seen_johnpoints1 = True
           [...]
           return
With your initial code, Ren'py was replaying the whole "johnroom" label when quitting the "johnpoints1" one. With this variation, it will return to scene johnpoints, which also avoid the infinite loop.



This said, there's also this :
Code:
           if time_points in [6,7,8,9,10,11,12]:
                       jump morning
           if time_points in [13,14,15,16,17]:
                       jump afternoon
           if time_points in [18,19,20,21,22]:
                       jump evening
You're working with literal numbers (by opposition to the representation of a number, like "1", "2", ...), therefore you can use direct comparison. And, like each condition exclude the others, it's better to have a single if block.
In the end, it looks like this :
Python:
           # Are time_points below 6 ?
           if time_points <= 5:
                       # Yes ? Alright, so we have nothing to do in this case
                       pass
           # Alright, time_points are above 5, but are they below 13 ?
           elif time_points <= 12:
                       # Yes ? Then it's time to go here
                       jump morning
           # So... time_points are above 12, but are they below 18 ?
           elif time_points <= 17:
                       # Yes ? Oh, really ? Then, go there please.
                       jump afternoon
           # And you can continue like this for hours...
           elif time_points <= 22:
                       jump evening
 

h0932377128

New Member
Sep 25, 2019
13
3
Thank you anne O'nymous. Can i ask you another question?

I am trying to add a code that will display the image depending on the points statement at the time. How should I write? I have tried but it's failed.

Code:
        if time_points in [6,7,8,9,10,11,12]:
             show image[1.png,2.png,3.png,4.png,5.png,6.png,7.png] at Position(xpos = 0.8, xanchor=0.5, ypos=0.5,                                yanchor=0.5)

How should I write correctly? Thanks
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,967
16,217
I am trying to add a code that will display the image depending on the points statement at the time. How should I write?
It depend of what you effectively intend to do.

For images that have few variations or variations depending of a range, you can use the displayable :

Python:
# Declare the image
image whateverImg = ConditionSwicth( 
       # If the value of time_points is between 6 and 12, the image
       # will be "images/myImg1.png".
       "time_points in [6,7,8,9,10,11,12], "images/myImg1.png",
       "time_points in [13,14,15,16,17,18], "images/myImg2.png",
       # Default condition. If all the previous conditions failed, 
       # the image will be "images/myImg0.png"
       "True", "images/myImg0.png" )

label whatever:
    show whateverImg
There's three images used here, "myImg0.png", "myImg1.png" and "myImg2.png"


You can use images made dynamic by text interpolation :
Python:
# The name of the file used will depend of the content of "time_points"
image whateverImg = "images/myImg[time_points].png"

label whatever:
   show whateverImg
There's many images used here, "myImg1.png", "myImg2.png", ... up to the maximal value possible for time_points.

You can build the image name directly in the code:
Code:
label whatever
    show expression "images/myImg{}.png".format( time_points )
Here again, there's many images used here, "myImg1.png", "myImg2.png", ... up to the maximal value possible for time_points.

Technically, the two previous case correspond to :
Code:
if time_points == 1:
    show "images/myImg1.png"
elif time_points == 2:
    show "images/myImg2.png"
elif time_points == 3:
    show "images/myImg3.png"
[...]
You can have a simple if structure like above.

There's other way to do it, but normally those four ways are enough most of the time.
 
  • Like
Reactions: h0932377128

h0932377128

New Member
Sep 25, 2019
13
3
anne O'nymous

if time_points == 1:
show "images/myImg1.png"
elif time_points == 2:
show "images/myImg2.png"
elif time_points == 3:
show "images/myImg3.png"
[...]

i know this way. But i'm trying to make this shorter. Because I have to copy and paste it everywhere. I have more than 40 image so it make a long list.
Each point will be an another image