how to stop my game when a variable is at a certain level ?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
squarecup
Newbie
Posts: 15
Joined: Fri Jan 19, 2018 2:28 pm
Contact:

how to stop my game when a variable is at a certain level ?

#1 Post by squarecup »

Hello,

So I've a variable "alcool" and when this variable is equal to 100 I would like the game to jump to an end I've wrote, and this whenever we are in the game, its depend of the choice we make.

Is it possible ?

Thanks for your answer

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: how to stop my game when a variable is at a certain level ?

#2 Post by PyTom »

How is your game structured? You could check it using a python callback, but frankly that's probably more complicated than it needs be. I'd suggest one of two things. If you have a main loop the game returns to, you can just do:

Code: Select all

label mainloop:
    if alcool >= 100:
        jump ending
Otherwise, I'd suggest defining a function that modifies alcool for you. Something like:

Code: Select all

init python:
    def update_alcool(change):
        global alcool
        alcool += change
        if alcool >= 100:
             renpy.jump("ending")
And then use it instead of updating the variable directly.

Code: Select all

    $ update_alcool(+10)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

squarecup
Newbie
Posts: 15
Joined: Fri Jan 19, 2018 2:28 pm
Contact:

Re: how to stop my game when a variable is at a certain level ?

#3 Post by squarecup »

PyTom wrote: Sun Jan 21, 2018 3:02 pm How is your game structured? You could check it using a python callback, but frankly that's probably more complicated than it needs be. I'd suggest one of two things. If you have a main loop the game returns to, you can just do:

Code: Select all

label mainloop:
    if alcool >= 100:
        jump ending
Otherwise, I'd suggest defining a function that modifies alcool for you. Something like:

Code: Select all

init python:
    def update_alcool(change):
        global alcool
        alcool += change
        if alcool >= 100:
             jump ending
And then use it instead of updating the variable directly.

Code: Select all

    $ update_alcool(+10)
Neither of them are working :/

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: how to stop my game when a variable is at a certain level ?

#4 Post by PyTom »

It isn't enough to say that they aren't working, you need to post an error message or say why.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

squarecup
Newbie
Posts: 15
Joined: Fri Jan 19, 2018 2:28 pm
Contact:

Re: how to stop my game when a variable is at a certain level ?

#5 Post by squarecup »

It's not that I have an error message, but when my variable alcool is > 100, the game continues

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3792
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how to stop my game when a variable is at a certain level ?

#6 Post by Imperf3kt »

What did you put in the label called 'ending'?
Where did you put it?

You can remove all the dialogue and post the code if you want some more in-depth help.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: how to stop my game when a variable is at a certain level ?

#7 Post by Remix »

Are you using
$ update_alcool( 5 )
or
$ alcool += 5
in the code?

Also, amend "jump ending" in the python function to something like "renpy.jump( 'ending' )"
Frameworks & Scriptlets:

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: how to stop my game when a variable is at a certain level ?

#8 Post by PyTom »

Yes, it was supposed to be renpy.jump("ending"). I've changed my example to fix that.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

squarecup
Newbie
Posts: 15
Joined: Fri Jan 19, 2018 2:28 pm
Contact:

Re: how to stop my game when a variable is at a certain level ?

#9 Post by squarecup »

Here's my code without the dialogue
ending.PNG
ending.PNG (7.49 KiB) Viewed 998 times
Maybe i don't put the label where they need to be...

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: how to stop my game when a variable is at a certain level ?

#10 Post by Remix »

PyTom was using pseudo-code for the mainloop example ...
Probably better to try the other way (especially if not using a game loop approach):

Code: Select all

default alcool = 0

init python:
    def update_alcool(change):
        global alcool
        alcool += change
        if alcool >= 100:
             renpy.jump("ending")

label start:
    "..."
    $ update_alcool( 50 )
    "..."
    $ update_alcool( 50 )
    "we never get here"

label ending:
    "we do get here"
    return
P.S. Rather than attaching an image, it is much better to actually copy-paste your code with forum tags -- [code]Your code here[/code]
Frameworks & Scriptlets:

squarecup
Newbie
Posts: 15
Joined: Fri Jan 19, 2018 2:28 pm
Contact:

Re: how to stop my game when a variable is at a certain level ?

#11 Post by squarecup »

I've tried your code and it's working perfectly ! Thank you so much !

Post Reply

Who is online

Users browsing this forum: No registered users