Ren'Py Need someone to tell me what I have done wrong

Amahl Farouk

Well-Known Member
May 13, 2018
1,320
2,436
Last night before I went to bed my code was working fine. I changed some label names to tidy things up and now my code doesnt cycle through the songs in my playlist. I cant figure out how to fix it. Please help ren'py python gurus!
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
First glance, (probably) completely unrelated to your current problem...

Your track and song lists should almost certainly be define and not default.

default is for variables that will change while the game is running and will be saved as part of the save files.

define is for variables that will never change while the game is running. They can be changed by the developer at any stage of development - just not by code ( $ ) while a player is playing.

I could be wrong about the daily song lists, depending on your plans for the future. But as it exists right now, it doesn't look like values of those lists will ever change while the game is running.

Keep in mind the "save file" thing too if you do stick with default. Values loaded from a save file will replace values currently stored by the game. So if you change anything in a future release - a player loading an earlier save file will load the "old" values, effectively reverting your "future change". btw, that is already true. Any testing you have done so far will have save files that will revert any changes to those lists if you load them.

Continuing to look...
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Second glance, and I'm still unsure if I'm on the right track - but it's setting off alarm bells...

I'd be happier with this answer if I could test it, but without the images, songs and fonts - it's purely a theoretical answer...

Okay...

Python:
    python:
        for song in day_1_song_list:
            renpy.call_screen("play_song", song)
    jump twenty_days_week1

renpy.call_screen() is the equivalent of ... which I tend to think of as "show screen but wait for player to click on something". There could be some quirk of doing it with renpy.call_screen(), but I would expect track 1 to get shown and nothing to happen until the player clicked on something (or some other action() is triggered).

But that is compounded by the for song in day_1_song_list:. Since day_1_song_list is 5 songs, it's almost like you're trying to show 5 different screens (one for each track)... Except they would all overlap and you wouldn't see the other 4 due to the one that shown on top. I don't think that is happening due to the call screen forcing the player to deal with track #1 before track #2 can be processed - but it looks unintentional and deeply flawed.


Then, within your screen play_song(song):, you have a "Return" imagebutton.

It's action() is action Call("twenty_days_weeks_menu"). Except is intended to "call" a label (not to be confused with call screen which behaves completely differently). is intended to jump to a label, do something and then return to where it came from using a statement. A list of labels that have been called is stored in something called a "call stack" and each time call is used, the stack gets one entry bigger (return reduces that stack by one). If you constantly call various labels without ever doing a return, the call stack can get so large that the game breaks. (The call stack is part of a save file, so things can so easily get out of hand).

I'm almost certain this should be an action Jump() or action Return().


None of which fixes your original problem, but hints at a series of compounded problems that may only now becoming obvious to you.

Will continue to look later today or tomorrow, as time allows...
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
If anyone else wants to play around with this one, find attached some dummy files I created so the project can be actively tested. Obviously, I don't know what the original sounds are like or the images either - these are just mockups I created.
 
  • Like
Reactions: LightmanP

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
It's action() is action Call("twenty_days_weeks_menu"). Except is intended to "call" a label (not to be confused with call screen which behaves completely differently). is intended to jump to a label, do something and then return to where it came from using a statement.
Be noted that the "where it came from" is not the screen. At the end of the called label, you'll be sent to the line following the call screen one.
You don't have permission to view the spoiler content. Log in or register now.


None of which fixes your original problem, but hints at a series of compounded problems that may only now becoming obvious to you.
Don't really have the time to look at this (I've a how-to to rewrite properly), but from what I saw through your investigation, I guess that the script was broke from the start. The changes he made didn't broke it, it just prevented it to works despite its errors.
You know, those cases where you're noticed about a bug, and once you've fixed it, you look at your code and wonder what magic made it works until now.


As for the loop, I guess that is intent was to play all song one after the other... while the game was still playing ; what would explain the use of a screen, here seen as something that come on top but don't prevent the game to advance.

If it's that, then he should have used and instead.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
As for the loop, I guess that is intent was to play all song one after the other... while the game was still playing ; what would explain the use of a screen, here seen as something that come on top but don't prevent the game to advance.

Right now, it's looking to me that the queueing method is akin to "show 5 screens... each with 1 song... then as the song finishes, continue to the next screen".

But it can't be that. *shrug*

Right now, I just want to burn it all down and rebuild it from the ground up.
 
  • Haha
Reactions: LightmanP

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Last night before I went to bed my code was working fine. I changed some label names to tidy things up and now my code doesnt cycle through the songs in my playlist. I cant figure out how to fix it. Please help ren'py python gurus!

Please read my previous replies, as they my help keep you on track as you continue to work on your project.

But right now, I also have a core question...

Is your current code a testbench for a future game? i.e. a proof of concept/technical build for something that will come later?
Or is this your whole project? Just something that plays music when you click on a button.
(may I suggest WinAmp or VLC? :devilish: )

Because it's not clear to me that this code is transferable into a larger project, with so much being dependant on custom screens.

I'm still looking at it, but I think I need a clearer idea of where you are heading with this, to try to make sense of how you got here.
If I had to guess, it feels like you're trying to add a custom playlist screen which is either shown all the time (like the quick_menu) or is toggled (like the preferences window).
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Right now, it's looking to me that the queueing method is akin to "show 5 screens... each with 1 song... then as the song finishes, continue to the next screen".
Oh but you're right, it's what it ask. But I'm as sure as you that it's absolutely not what OP wanted it to do.

Would that be pure screens, why not, one can want to have more than one screen displayed in the same time. But here it's supposed to play music, and I absolutely not see someone wanting to play 5 musics in the same time.
So, I tried to understand what was the intent, and goes for what seem the less illogical.

But well, I guess that my times doing reverse engineering as part of my security admin job help me to look at codes in a "what did he wanted to do" way. It's a habit that come quickly when you've just access to partial information.


Right now, I just want to burn it all down and rebuild it from the ground up.
Yeah, I know this feeling, I have it each time I look at the code you I wrote ten years ago ; older than that it should be illegal to look at it.

Edit: what the fuck where I thinking ? Typo corrected.
 
Last edited:

Amahl Farouk

Well-Known Member
May 13, 2018
1,320
2,436
Hi thank you so much for all your input

So to answer a few questions as to the aim of the thing. Once a person clicks a particular day's files, all the files are designed to play one after the other until the list is complete. The only interaction the player has is to pause the file or quit out of it, or return to the previous screen. When an audio file is being played the name of the file is displayed (the 150 font thing) and the progress bar, and the pause, quit and return buttons

I am REALLY new to programing as you can see from my code and I really do appreciate your help here. It will take me a few days to go through your suggestions but I will be sure to let youknow how I get along

It is really odd how I somehow managed ot break it, before I started changing a few label names it worked great

Thats another example of poor programming, not making notes and backups before major changes

The game itself right now is a simple playlist player but later on it will be able to allow a player to build their own playlists that they can save and play and also a feature where a player can spend points accrued by listenign files to develop an avatar

Does that make any sense?
 

Amahl Farouk

Well-Known Member
May 13, 2018
1,320
2,436
This game/ playlist player is based around a self hypnosis system that has defined files to be played in order on particular days
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Once a person clicks a particular day's files, all the files are designed to play one after the other until the list is complete. [...]
The real question is: Is the player expected to just seat there, doing nothing else than listening to those music ?

Because as you write your code, it's what happen ; well, what would happen if the few errors where corrected.


I am REALLY new to programing as you can see from my code and I really do appreciate your help here.
One last advice: There's a documentation with Ren'Py SDK. It's in the "doc" folder at the same place where you put the said SDK. Drag&drop one of the HTML page (preferably the "index.html" one) into your browser and start reading it.
It's not always easy to understand, but by looking at the "audio" part you would have found the answer to your problem ; the play and queue statement I mentioned in a previous post.


It is really odd how I somehow managed ot break it, before I started changing a few label names it worked great
Not really odd, it's relatively frequent, especially with people that don't have much experience.

Imagine that you buy a picnic table. All summer you use it when you go to the beach and everything is fine. Then one day, for Christmas by example, you need a secondary table at home, and decide to use it. And it's a catastrophe, the legs don't all have the same length, the table is unusable.
The default was there from the start, but it's only now that you use the table on a steady ground that you can notice it.

It's the same that happened with your code. For some reason it worked, but it was broke from the start, and while changing the labels, you remove the fix that was making works despite its problems.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
So, it would be something like...

The player wakes up and picks (or creates their own) playlist which plays as background music and then the game continues with what ever else is going on for that day.

I assume that (in theory at least), the player can return to the playlist selection screen at any point during the gameplay and pause/stop or reorganize a new playlist.

Then you'll have some mechanic that rewards players for picking the right combination of songs/tracks for a given day.

... or something vaguely like that.

I'll continue to have a play, but I'll mainly wait to see how much sense my other feedback makes to you and let you apply what I've said above to your own code. After all, the point here is to end up with code YOU understand - since you're the one who will have to continue to work on it.

(and yeah, I tend to agree with Anne... I don't think this was working as well as you thought it was from the start).

Edit: As another viewpoint on a similar problem... you might want to have a look a this thread I was involved with a little while ago. In it, we were playing around with random playlists. This particular post includes a downloadable "game" which has a lot of the audio functions I think you're going to end up needing.
It's not an exact match to what you're doing, but there is certainly an overlap.
https://f95zone.to/threads/a-deeper-understanding-of-renpy-audio-queue.95461/post-6663668
 
Last edited:

Amahl Farouk

Well-Known Member
May 13, 2018
1,320
2,436
Hi there! Just following up with you guys!

I finally got a solution to my problem with the player so I thought I would share it with you

script


Python:
init python:
    config.default_fullscreen = True

    done = "images/done.png"
    path = ""

    playingpoint = 0

    playingcode = 0

    class Song:
        def __init__(self, name, file, length):
            self.name = name
            self.file = file
            self.length = length
            self.has_played = False
           

    class Playlist:

        def __init__(self, name, list):
            self.name = name;
            self.list = list;
            self.has_played = False

        def hasplayed(self):
            #   self.has_played = True # For testing purposes :3
            if(self.has_played == True) :
                final = done
            else :
                final = "images/"+self.name+".png"

            return final

screens

Python:
screen play_song(song, startpoint = 0):
    on "show" action Play("music", "<from {point}>".format(point = startpoint)+song.file, loop=None
    )
    text "{song_name}".format(song_name = song.name)  font "fonts/DollieScriptPersonalUse-K3P7.ttf" size 150  xalign 0.5 yalign 0.3

    timer song.length-startpoint action [SetVariable("song.has_played", True), SetVariable("playingcode", 2), SetVariable("playingpoint",0), Return()]

    bar:
        value AudioPositionValue(channel='music',update_interval=0.1)
        xalign 0.5
        yalign 0.5
        xsize 500
        xmaximum 50

    imagebutton:
        xalign 0.1
        yalign 0.9
        xoffset -30
        yoffset 30
        idle "images/return.png"
        hover "images/returnhover.png"
        action Call("play_lists")

Everything is working really well, thanks for taking the time to help me!