Ren'Py [SOLVED] Screens seems to take time to load for some reason

nonomo

Newbie
Game Developer
May 2, 2019
43
68
So, I'm still trying to make a game in ren'py. I'm still learning the engine while coding so I don't know everything.
I've come across a problem that I can't wrap my head around.
For some reason, every time I call my screens, the game take something like 0.5 seconds to load them. It's not that much but when there a few steps repeating it becomes jaring.

Here's my typical code when I start a new scene and screens are called :

Code:
label library1_play:
    scene library1
    $ in_library1 = True
    call screen library1_screens
    jump library1_play


screen library1_screens:
    imagebutton:
        focus_mask True
        idle "library1_to_main_hall"
        hover im.MatrixColor("/images/screens/school/library1/library1_to_main_hall.webp", im.matrix.brightness(.1))
        action [SetVariable("in_library1", False), Jump("main_hall_set")]
    if time_day == "Early morning":
        imagebutton:
            at eina_pos_library
            focus_mask True
            idle im.MatrixColor("/images/characters/schoolcharacters/eina/eina_camview.webp", im.matrix.brightness(-.15))
            hover im.MatrixColor("/images/characters/schoolcharacters/eina/eina_camview.webp", im.matrix.brightness(-.05))
            action Jump("talk_to_eina")
I thought about image size but I don't think that's the problem as there are instances where I show something around 6 to 10 images at the same time and it goes flawlessly as long as those are not screens.
Is this something known, am I missing something ? Anyway, thanks a lot for your help in advance.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,610
2,257
Can't be sure, but the above code looks fine.

Half a second?
I'm guessing a transition is being used, either directly or indirectly.

Hopefully the word "transition" has trigger some sort of memory in you, like "Oh, yeah... I remember changing the default transition to with dissolve" or something.
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Can't be sure, but the above code looks fine.

Half a second?
I'm guessing a transition is being used, either directly or indirectly.

Hopefully the word "transition" has trigger some sort of memory in you, like "Oh, yeah... I remember changing the default transition to with dissolve" or something.
Well, if I put a transition like with dissolve, there's the 0.5 sec where nothing happens THEN the transition starts.
There was with dissolve in the beginning but I removed it to see if that was the problem.
I can add that it doesn't happen every time. Let's say I have three places like this : room1, hallway, room2. I start from room1
the first time I go to hallway the lag happens. then if I switch from room1 to hallway any number of times it doesn't happen anymore.
but if I go to room2, going back to hallway then room1, the lag happens again.
 
Last edited:

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,750
16,555
Missing parameter list for the screen - library_screen():
im is obsolete, use Transform
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Missing parameter list for the screen - library_screen():
I already tried the parameter list it doesn't change a thing.

im is obsolete, use Transform
the delay occurs even if I put only an image button like this :
Code:
imagebutton:
        focus_mask True
        idle "library1_to_main_hall"
        action [SetVariable("in_library1", False), Jump("main_hall_set")]
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,610
2,257
Well, if I put a transition like with dissolve, there's the 0.5 sec where nothing happens THEN the transition starts.
There was with dissolve in the beginning but I removed it to see if that was the problem.

It was a guess on my part, since the code you've included looks fine and you specifically mentioned "0.5 seconds".

Your code didn't include an explicit with dissolve or similar - so I assumed code you might have used but hadn't thought worthy of mention (it's very common here in the dev forum).

There are configuration variables like or other . Using them is very rare (especially for new developers) and therefore you would likely remember if you'd used any of them. I was hoping that you might have seen a random bit of code somewhere that included one of these configuration variables and decided that it looked like a good idea and used it.

But clearly you haven't - and so it's likely my guess is wrong. But the "0.5 second" points to something similar.
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
But clearly you haven't - and so it's likely my guess is wrong. But the "0.5 second" points to something similar.
Yeah well, I try my best to not put things in my code that I do not understand. I restarted the project a few times already to have something cleaner everytime.
Now, after a bit more of testing, the delay isn't the same every time. If there are more images in the screen then it will take longer. It really seems like it's a loading problem. But it doesn't happen when I just show multiple images that are not in screens.
 
Last edited:

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,504
8,038
Try this: (Predict the screen, and perhaps increase the size as well).
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Try this: (Predict the screen, and perhaps increase the size as well).
Hmmm, at first glance this seems to work. But that would mean I would have to add a lot of those lines in every start of a new scene right ?
Also, do I have to stop predicting all of them every time ? Or changing the scene clears that memory ?

So I take that where I'm at, the engine struggles to predict what screens are coming next ?

And what do you mean by increase the size ? The size of what ?
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,504
8,038
config.image_cache_size and config.predict_statements
There's no correct value, it all depends on your game and needs.

If that fixes your issue, then it is simply a prediction problem. Ren'Py preloads that stuff automatically (prediction), it should work with screens as well but for some reason it doesn't do so automatically in your case.
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Okay, Thank you all for your help.
I'll try to see what I can do about all of this.
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,504
8,038
Also, do I have to stop predicting all of them every time ? Or changing the scene clears that memory ?
It would be more clean to stop predicting when you are done with it, but Ren'Py automatically frees up the cache when it needs space to store new entries. I am not completely sure whether screens are forced to stay in the cache until you stop them or not, but you can see a list of predictables by accessing the developer menu (Image Load log).
This is also how you can more or less tell which values your game needs in config.image_cache_size and config.predict_statements (As Image load log shows the usage of both).
For instance if you see that not enough images are getting predicted, you should increase the predict statements, whereas if you see that your cache is quickly running out of memory, then you need to increase the cache size.
 
  • Like
Reactions: nonomo

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Right. So now, increasing those values doesn't stop the loading to happen the first time.
but it only does it once. Afterwards everything goes smoothly.
For the image cache, is it better to have it around at high percentage or not ?
 

nonomo

Newbie
Game Developer
May 2, 2019
43
68
Looking at the image load log, I see that my game fails to predict anything before seeing it once.
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,504
8,038
For the image cache, is it better to have it around at high percentage or not ?
The percentage, if I recall correctly, is the amount occupied by the cached images. If it is high, and it is not predicting enough, then it needs a bigger size. You can more or less calculate it like so:
(width * height * 4) * N of images you want to predict.
 

nonomo

Newbie
Game Developer
May 2, 2019
43
68
The percentage, if I recall correctly, is the amount occupied by the cached images. If it is high, and it is not predicting enough, then it needs a bigger size. You can more or less calculate it like so:
(width * height * 4) * N of images you want to predict.
Hmmm, the strange thing is : even if the cache is at 5%, it's not predicting anything. Now however, it slows only the first time i load a new place.
 

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,750
16,555
What kind of an image is it and what's the resolution? What Ren'Py version are you using? Is there a lot of transparency? focus_mask is not efficient compared to an image with no transparency, might be something.
Are you using a potato?
 

nonomo

Newbie
Game Developer
May 2, 2019
43
68
What kind of an image is it and what's the resolution? What Ren'Py version are you using? Is there a lot of transparency? focus_mask is not efficient compared to an image with no transparency, might be something.
Are you using a potato?
Images are 1920x1080, Ren'Py version is 8.0.3, without focus_mask if the image is not a square there will be collision I don't want.
And finally no, my pc is not a potato. I don't know the spec by heart but I can run recent games at their best visuals without much trouble.
also, I decided to try the same images and screens in a new project. The problem doesn't occur apparently. I don't understand why.
I guess I'll redo the project once more.
 
Last edited: