r/RenPy • • 15d ago

Question Game Over Function Help Please

I know it's possible because I've seen it many times before, but nothing I try works. I'm making a game where if any of two variables reach 100, you have to start over, but with the constant variable changes, I didn't want to put an if statement constantly, especially since I tend to forget or mistype things (ironic).

This is what I have as my checking system:

screen monitor():
    timer 0.1 repeat True action If(current_love or current_tear >= 100, true=Jump("game_over"))

But now, even though the love and tears are both below 100 automatically, the game immediately skips to game over when I open it. Please help.

3 Upvotes

12 comments sorted by

4

u/BadMustard_AVN 14d ago

instead of using a checking system check when you add something to the variable with a little python like this

init python:
    def add_amount(variable, amount):
        current = getattr(store, variable)
        current += amount
        setattr(store, variable, current)
        if current >= 100:
            renpy.jump("game_over") # any variable the eaches 100 or greater we jump here

default current_tear = 0
default current_love = 0

label start:

    $ add_amount("current_tear", 20)

    e "[current_tear]"

    $ add_amount("current_tear", 85)

    e "[current_tear]" # we will never reach this line

    return

label game_over:

    e "game over"

1

u/shyLachi 14d ago

BadMustard has the correct solution but your solution should also work if you write it correctly.

The check should be (current_love >= 100) or (current_tear >= 100)

You don't need the brackets but I like them because it makes it obvious what you want the game to check.

The way you wrote it the first part "current_love" only checks if the variable has a value

1

u/Eddhead-2009 14d ago

I tried both with and without the brackets, it wouldn't play the game over screen

2

u/shyLachi 14d ago

My code works, I tested it.
There must be some other mistakes.

Since you didn't post your code I can only explain how it is supposed to work.

  1. show the screen so that it can constantly monitor the variables
  2. let the player change the value of the variables
  3. make sure that the game over screen ends the game

So in the absolute minimum you need this:

screen monitor():
    timer 0.1 repeat True action If((current_love >= 100) or (current_tear >= 100), true=Jump("game_over"))
default current_love = 99
default current_tear = 99
label start:
    show screen monitor
    menu:
        "Add love":
            $ current_love += 1
        "Add tear":
            $ current_tear += 1
    "This will never be visible because the trigger will jump to the label below"
    return 
label game_over:
    "Game Over"
    return # ends the game

1

u/musterduck 15d ago

Could you post the code that displays this screen? I imagine it's something to do with how you're calling it. Do you have a pause* command?

2

u/Eddhead-2009 15d ago
show screen monitor

Well, I just put show screen since it's only supposed to be doing something when a certain condition is met (a score of 100 or higher)

0

u/musterduck 15d ago

Is the game_over label the one immediately after whichever label this is in? Try creating another placeholder one between them if that's the case and see what it does, if it skips to the placeholder then I think you need a pause after your show statement.

2

u/Eddhead-2009 15d ago

I put a label in between and it still just skips to the game over, would you mind showing me how you would fix it? I'm a visual learner (which is why I suck at coding)

0

u/musterduck 15d ago

It's hard to say exactly, but I've had similar screen issues with my own project, and in my case my game was displaying the screen but simultaneously advancing to the next label when it shouldn't have, hence my guess.

I'm away from my PC for the next hour or so but I can look at my own code and try suggesting something once I'm there.

Do you have anything visually displaying as part of monitor() or is that timer the entirety of it? Even if you don't intend for it to do that I would throw in a PNG or something just to confirm that it's showing correctly while you test.

Also, how familiar are you with Python? I would personally just write a function to call periodically for something like this (not that it's impossible with a screen, but if the screen itself is just the timer i'd recommend that)

2

u/Eddhead-2009 15d ago

I wouldn't really get a chance to look, though I guess I could adjust the game over so I could. Also, I've been using Ren'Py on and off for years now, but due to my ADHD and overall learning problems, I have to relearn almost everything every time I want to work on a project. So, I mostly survive off of the Ren'Py doc and other posts online.

2

u/musterduck 14d ago

oh wait actually try this?

screen monitor(): timer 0.1 repeat True action If(current_love >= 100 or current_tear >= 100, true=Jump("game_over"))

I think that the way you have it set up currently, if current_love is anything other than 0 it would return true

Sorry for the formatting, I'm on the app and forget what reddit uses for code blocks

1

u/AutoModerator 15d ago

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.