how to stop my game when a variable is at a certain level ?
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.
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.
how to stop my game when a variable is at a certain level ?
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
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
- 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 ?
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:
Otherwise, I'd suggest defining a function that modifies alcool for you. Something like:
And then use it instead of updating the variable directly.
Code: Select all
label mainloop:
if alcool >= 100:
jump ending
Code: Select all
init python:
def update_alcool(change):
global alcool
alcool += change
if alcool >= 100:
renpy.jump("ending")
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(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: how to stop my game when a variable is at a certain level ?
Neither of them are working :/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:
Otherwise, I'd suggest defining a function that modifies alcool for you. Something like:Code: Select all
label mainloop: if alcool >= 100: jump ending
And then use it instead of updating the variable directly.Code: Select all
init python: def update_alcool(change): global alcool alcool += change if alcool >= 100: jump ending
Code: Select all
$ update_alcool(+10)
- 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 ?
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(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: how to stop my game when a variable is at a certain level ?
It's not that I have an error message, but when my variable alcool is > 100, the game continues
- 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 ?
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.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- 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 ?
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' )"
$ 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:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- 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 ?
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(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: how to stop my game when a variable is at a certain level ?
Here's my code without the dialogue
Maybe i don't put the label where they need to be...- 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 ?
PyTom was using pseudo-code for the mainloop example ...
Probably better to try the other way (especially if not using a game loop approach):
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]
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
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: how to stop my game when a variable is at a certain level ?
I've tried your code and it's working perfectly ! Thank you so much !
Who is online
Users browsing this forum: No registered users