Ren'Py No idea why boolean doesn't work

kinkiusagi

New Member
Jan 18, 2023
4
2
Hi and sorry to start my first post with a burning question right away, but that's why I signed up here.

I am currently tinkering with an AVN, but I am absolutely no programmer. I'm reading up and spending a lot of time trying, but I could use some help from professionals. Please, help a noob - you'll get some kinky stuff in the end.

I have defined images, but animated ones. (Maybe that's the problem). Now I want to exchange the images of the talking persons in a dialog with true/false statement. That works too, but only the first time. After the first True should come False and therefore Else, but it stays on True:

You don't have permission to view the spoiler content. Log in or register now.


You don't have permission to view the spoiler content. Log in or register now.

If anyone could push me in the right direction ... that'd be amazing.

P.S.:
i also do not understand why
ep0madison_talking
ep0madison_casual
is not automatically replaced? shouldn't the same prefix image replace the previous one?
 

voronkov

Member
Aug 27, 2018
288
241
Лучше бы скриншот кода а не написание. На скриншоте будет понятно что и как, а тут не очень. НЕ очень понял вопрос но можешь просто добавить
if richard_talking == False: вместо else: и по идее может быть будет работать.


A screenshot of the code would be better than writing. On the screenshot it will be clear what and how, but not so much here. I didn't really understand the question, but you can just add
if richard_talking == False: instead of else: and in theory it might work.
 

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
995
Hello.
when posting code, use the Insert/Code instead of spoiler. This is to make sure you are 'tabbing' your code correctly, as right now the code doesn't looked to be tabbed over, which means that it ignores the if and else statements.

as for why ep0madison_talking isn't being replaced, there's a few things going on, you are doing a few things at the same time, several assumptions at once. To be honest, trying to explain it is like when I first started as an engineer, where the place i worked was making schematics using 100 different techniques all mashed together because they didn't know what they were doing. It looks like you are doing something that seems simple to you, but as someone who does a lot of programming, I see you trying to do several things at once, and trying to get this to work 'as is' is more effort than just trying to recode it right.

First, what are you trying to do. it looks like you are trying to describe a scene with 2 people. you are using this scene sort of like a description, or definition, something you can reuse. either Richard is talking, or Richard is not talking (Madison is talking instead). this way you don't have to constantly use show and hide between each line of dialog. What might be easier is to make 2 separate scenes, and use them like some sort of dialog command, something like this

Python:
label start:
    jump talk_with_richard_1 # this will be the scene
  
label talk_with_richard_1: # outline the scene
    scene ep0_bg
    show ep0madison casual with dissolve
    show ep0richard casual

    #scene set up complete

    #now to do the actual scene, line by line

    """you did good here, having both start in a casual pose,
    Noticed I removed the '_' underscore,
    this way renpy can figure out that 'ep0madison' and
    'ep0richad' are the subjects, and the 'casual' is the attribute
    this will allow renpy to automatically replace one with the other.
    this means you have to remove the _ when making the images
    (this is a feature I've only seen in renpy, in all other cases
    you would have to do something like what you did with the variable
    richard_talk)
    """

    #calling different scenes and passing in a parameter
    # this way you have no need to set $richard_talking = True
    call ep0madison_says("Hello")
    call ep0richad_says("I like Cocaine")
    call ep0madison_says("Uh... Ok")
    call ep0richad_says("I'm going to do some cocain now, bye!")
    call ep0madison_says("... wtf?")
    #end scene/game

    #if you still wanted to use $richad_talking then
label example:
    if richard_talking == True #your if statement here, not mixed in with everyhting else
        call ep0richad_says
        return # this will skip all other code by forcing a return now
    # else: not needed because of the above return
    call ep0madison_says
    return # something I need to double check, if a return is nessesary or not

# separate your code out so that you are not mixing everything in one block of code
# this is just an example of clean/good coding practices
label ep0richard_says(what):  # from if richard_talking == true
    hide ep0richard_casual
    # TO DO (for me) figure out how to replace this with ep0richard casual
    # and make sure that it auto replaces ep0richard talking, and vise versa
    show ep0richard_talking
    hide ep0madison_talking
    show ep0madison_casual
    richard what # makes richard say the text

label ep0madison_says(what): # from if richard_talking == false
    hide ep0richard_talking
    show ep0richard_casual
    hide ep0madison_casual
    show ep0madison_talking
    madison what # makes madison say the text
Now I am very new to renpy as well, little over 2 weeks of code, but over a decade of C# so I don't know if the above is the best way to go about coding in renpy, as you'll see I'm not confident enough to know if simply removing the '_' and using the subject/attribute system of renpy will do the auto replace you are looking for, but this would be my intuition. Basically the point being, clean up the code by breaking it down into reusable parts, rather than trying to make a big block with lots of if statements.
 
  • Red Heart
Reactions: kinkiusagi

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,163
14,874
If anyone could push me in the right direction ... that'd be amazing.
Code is processed in order of appearance, therefore when you have:
Python:
label whatever:
    if flag == True:
        show this
    else
        show that
Everything that will follow will not change what is already done.


But Ren'Py is a game engine that handle dynamism relatively well. It come with different ways to do it in real time, updating what is shown depending of a context change. In your case, there's three ways to do what you want. From the most accurate to the more complex, those ways are:

  • The use of a displayable

    It's a displayable that will show one image or another (strictly speaking you can have as many alternative as you want) depending on a condition. Here, the condition would be: what is the value of richard_talking flag.

    You don't have permission to view the spoiler content. Log in or register now.
  • The use of

    They are intended for way more advanced constructions, and totally misused here. But I feel that pointing you to this feature, not to solve this case but to make you know that it exist, can be a good idea.

    You don't have permission to view the spoiler content. Log in or register now.
  • Relying on text interpolation in the image declaration

    /!\ This method is way more advanced and not the best fit in your case /!\
    Sill I present it because it's an alternative, and it can be really useful for more advanced projects. Therefore it can interest some readers (Saki_Sliz )
    It rely on the fact that an image declaration works in the same way than text, therefore [variableName] will be replaced in real time by the value of "variableName".

    You don't have permission to view the spoiler content. Log in or register now.
 

kinkiusagi

New Member
Jan 18, 2023
4
2
Thank you so much for the feedback, all of you. (Also, I'll be posting code the next time with the insert/code option.

I have done some little (non sexual - not that it matters) renpy scenes before. I always did dialogue

show A talking
show B casual
A "blabla"
hide A talking
show B talking

... and so on. I just thought, that there would be a more elegant way to do it.
So, thanks for your suggestions, gonna try it now. <3
 

kinkiusagi

New Member
Jan 18, 2023
4
2
So, as Saki_Sliz said, deleting the "_" helped, to do what I tried to achieve in the first place. It worked.


You don't have permission to view the spoiler content. Log in or register now.


But I still want to do it in a more beautiful way. So I tried Saki_Sliz' "call":

You don't have permission to view the spoiler content. Log in or register now.

It gives me following error. Me, having no idea of what I am doing ("mr. captain of the titanic, do you even know where we are going?", "Off course"), tried to play around with : in the end or putting what into () but I didn't find out, what the problem was. In most of my variations and tries, the error message got way longer. ^^

You don't have permission to view the spoiler content. Log in or register now.


I also tried anne O'nymous' code. Example 1 doesn't get me an error, though it also doesn't change the images from casual to talking. both characters stay casual through the dialogue.
I also tried the second version with the if/else layered image: again, no error message, but the characters don't change and stay casual.

You don't have permission to view the spoiler content. Log in or register now.

You don't have permission to view the spoiler content. Log in or register now.




Anyway - soooo much thanks! Even if I haven't found out yet, how to do it or what the problem is - seeing code from people, who have more understanding of it, helps me to get a hint on how the whole coding thing works, what is possible and how to think in this language.
 

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
995
/!\ This method is way more advanced and not the best fit in your case /!\
Sill I present it because it's an alternative, and it can be really useful for more advanced projects. Therefore it can interest some readers
Sometimes I worry if this site has notifications for when someone bookmarks a post... cuz I bookmark a lot of yours...

File "game/episodes/000_intro_scene.rpy", line 98: expected statement. madison what ^
Sorry about that, I still haven't learned intuitively what renpy/python is and isn't able to process yet, replace what with "[what]" to get it to work
 
  • Like
Reactions: kinkiusagi

kinkiusagi

New Member
Jan 18, 2023
4
2
Thank you again and sorry for the late response - last days have been a little too much real life action and too less computer time.

replacing what with "[what]" nearly worked - still got an error, but I am a little proud, I found the solution. This way it works:

Code:
label ep0richard_says(what):  # from if richard_talking == true
    hide ep0richard_casual
    show ep0richard talking
    hide ep0madison talking
    show ep0madison casual
    richard "[what]"
    return

label ep0madison_says(what): # from if richard_talking == false
    hide ep0richard talking
    show ep0richard casual
    hide ep0madison casual
    show ep0madison talking
    madison "[what]"
    return
So it needed "return", otherwise it said madisons "what" had no value.

I am especially thankful, because I think I can use that "call" method for other things like changing an outfit according to players choice and so on.
 
Last edited: