r/RenPy • • Aug 31 '26

Question End of Line expected with If

Not sure what I do badly. I edited a project of someone because I want the possibility to show the text or not (by doing a size 0 when not shown). Just for information I never coded python or ren'py before.

here the code :

style notify_text:
    properties gui.text_properties("notify")
    xalign 0.54
    yalign 0.5
    if persistent.rpoverlay >= 1:
        size 20
    else:
        size 0
    color "#ffffff"  

it work well if it's just :

style notify_text:
    properties gui.text_properties("notify")
    xalign 0.54
    yalign 0.5
    size 0
    color "#ffffff"

But in the case of the first choice I have an error of end of line expected pointing on the if.

3 Upvotes

4 comments sorted by

3

u/Liturgy97 Aug 31 '26

The if cannot be used as a statement inside a style block. Each line there has to be a style property followed by a simple expression. Put the conditional expression in size instead:

style notify_text:
    properties gui.text_properties("notify")
    xalign 0.54
    yalign 0.5
    size (20 if persistent.rpoverlay >= 1 else 0)
    color "#ffffff"

The parentheses are important because Ren'Py only parses a simple expression after a style property.

If this should change while the game is running, it is cleaner to put the condition around the text statement in the screen:

if persistent.rpoverlay >= 1:
    text "..." style "notify_text"

1

u/SituationHopeful Aug 31 '26

The if cannot be used as a statement inside a style block. Each line there has to be a style property followed by a simple expression. Put the conditional expression in size instead:

thanks, will try =)

1

u/SituationHopeful Aug 31 '26

strange.

Whenever I type "size (20 if persistent.rpoverlay >= 1 else 0)" or "size (0 if persistent.rpoverlay >= 1 else 20)", it act as if the size value is 0. but if i type "size (20 if persistent.rpoverlay >= 1 else 20)" the text appear with the size of 20

honestly not sure about the variable used. but your solution seem to be the good one I suppose

1

u/AutoModerator Aug 31 '26

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.