Is there a way to make interruptions based on a variable?
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.
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Is there a way to make interruptions based on a variable?
Hi I'm sorry if this has been answered before, I didn't know what words to be looking for to find an answer for this question if it had already been handled, I'm using Ren'Py if that helps you provide answers
I was wondering if there's a way to cut away to some event if certain conditions are filled with a variable
For example in the following situation if your "Health" was 3 you should die in the middle here
"You open the lid of the treasure chest and set off a nasty trap"
$ Health -= 5
"You find a potion of healing inside and drink it immediately"
$ Health += 15
"You feel right as rain!"
"(Dialogue with companions and generally the story keeps going)"
I mean I know I could just do something like:
"You flip open the lid of the treasure chest and set off a nasty trap"
$ Health -= 5
if Health <1:
jump death
But in a story where some sort of "keep above 0 or you lose" variable is used a LOT I wondered if there were some easier way to do things so that it will jump to the death label if "Health" ever drops below 1
I was wondering if there's a way to cut away to some event if certain conditions are filled with a variable
For example in the following situation if your "Health" was 3 you should die in the middle here
"You open the lid of the treasure chest and set off a nasty trap"
$ Health -= 5
"You find a potion of healing inside and drink it immediately"
$ Health += 15
"You feel right as rain!"
"(Dialogue with companions and generally the story keeps going)"
I mean I know I could just do something like:
"You flip open the lid of the treasure chest and set off a nasty trap"
$ Health -= 5
if Health <1:
jump death
But in a story where some sort of "keep above 0 or you lose" variable is used a LOT I wondered if there were some easier way to do things so that it will jump to the death label if "Health" ever drops below 1
- PyTom
- Ren'Py Creator
- Posts: 16093
- 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: Is there a way to make interruptions based on a variable
Perhaps something like:
Code: Select all
default check_health = True
default Health = 42
init python:
def health_callback():
global check_health
if check_health and Health <= 0:
check_health = False
renpy.jump("death")
config.python_callbacks.append(health_callback)
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
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Re: Is there a way to make interruptions based on a variable
Recives this error:PyTom wrote:Perhaps something like:
Code: Select all
default check_health = True default Health = 42 init python: def health_callback(): global check_health if check_health and Health <= 0: check_health = False renpy.jump("death") python_callbacks.append(health_callback)
File "game/script.rpy", line 10: expected statement.
default check_health = True
File "game/script.rpy", line 11: expected statement.
default Health = 42
(Errors were actually pointed to with arrows in the program, since the spaces didn't move the arrow to the right spot in this post I have turned them red instead)
Also I used health because it seemed like the easiest to make an example for the concept, the actual variable using this in what I'm currently working on is called time (Edit: Though I ran the test with both the word "health" and "time" and it got the same result)
- PyTom
- Ren'Py Creator
- Posts: 16093
- 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: Is there a way to make interruptions based on a variable
Are you on an older Ren'Py?
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
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Re: Is there a way to make interruptions based on a variable
It said "Ren'Py Version: Ren'Py 6.99.3.404" at the bottom of the error window, sorry, I guess I should have included that
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Re: Is there a way to make interruptions based on a variable
Updated and tried the same code, it came up with:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 9, in script
init python:
File "game/script.rpy", line 16, in <module>
python_callbacks.append(health_callback)
NameError: name 'python_callbacks' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "D:\Programs\renpy-6.99.3-sdk\renpy\bootstrap.py", line 281, in bootstrap
renpy.main.main()
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 401, in main
game.context().run(node)
File "game/script.rpy", line 9, in script
init python:
File "D:\Programs\renpy-6.99.3-sdk\renpy\ast.py", line 805, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "D:\Programs\renpy-6.99.3-sdk\renpy\python.py", line 1461, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 16, in <module>
python_callbacks.append(health_callback)
NameError: name 'python_callbacks' is not defined
Windows-8-6.2.9200
Ren'Py 6.99.8.959
Mysterious_Fosters 0.0
Line 9 was init python and 16 was "python_callbacks.append(health_callback)" (Edit: Again tried it with both "Health" and "time")
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 9, in script
init python:
File "game/script.rpy", line 16, in <module>
python_callbacks.append(health_callback)
NameError: name 'python_callbacks' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "D:\Programs\renpy-6.99.3-sdk\renpy\bootstrap.py", line 281, in bootstrap
renpy.main.main()
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 401, in main
game.context().run(node)
File "game/script.rpy", line 9, in script
init python:
File "D:\Programs\renpy-6.99.3-sdk\renpy\ast.py", line 805, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "D:\Programs\renpy-6.99.3-sdk\renpy\python.py", line 1461, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 16, in <module>
python_callbacks.append(health_callback)
NameError: name 'python_callbacks' is not defined
Windows-8-6.2.9200
Ren'Py 6.99.8.959
Mysterious_Fosters 0.0
Line 9 was init python and 16 was "python_callbacks.append(health_callback)" (Edit: Again tried it with both "Health" and "time")
- PyTom
- Ren'Py Creator
- Posts: 16093
- 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: Is there a way to make interruptions based on a variable
Sorry, it should be config.python_callbacks.append
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
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Re: Is there a way to make interruptions based on a variable
If I'm meant to remove the (health_callback) from the end then the program runs without popping up an error window but dropping below 1 doesn't actually do anything
If I'm meant to leave the (health_callback), on the end of config.python_callbacks.append, then I get this error:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "renpy/common/00start.rpy", line 138, in script call
call _start_store
File "renpy/common/00start.rpy", line 106, in script
python hide:
File "game/script.rpy", line 12, in health_callback
if check_health and Health <= 0:
NameError: global name 'check_health' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "D:\Programs\renpy-6.99.3-sdk\renpy\bootstrap.py", line 281, in bootstrap
renpy.main.main()
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 468, in main
run(restart)
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 139, in run
renpy.execution.run_context(True)
File "D:\Programs\renpy-6.99.3-sdk\renpy\execution.py", line 714, in run_context
context.run()
File "renpy/common/00start.rpy", line 138, in script call
call _start_store
File "renpy/common/00start.rpy", line 106, in script
python hide:
File "D:\Programs\renpy-6.99.3-sdk\renpy\ast.py", line 810, in execute
i()
File "game/script.rpy", line 12, in health_callback
if check_health and Health <= 0:
NameError: global name 'check_health' is not defined
Ren'Py 6.99.8.959
If I'm meant to leave the (health_callback), on the end of config.python_callbacks.append, then I get this error:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "renpy/common/00start.rpy", line 138, in script call
call _start_store
File "renpy/common/00start.rpy", line 106, in script
python hide:
File "game/script.rpy", line 12, in health_callback
if check_health and Health <= 0:
NameError: global name 'check_health' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "D:\Programs\renpy-6.99.3-sdk\renpy\bootstrap.py", line 281, in bootstrap
renpy.main.main()
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 468, in main
run(restart)
File "D:\Programs\renpy-6.99.3-sdk\renpy\main.py", line 139, in run
renpy.execution.run_context(True)
File "D:\Programs\renpy-6.99.3-sdk\renpy\execution.py", line 714, in run_context
context.run()
File "renpy/common/00start.rpy", line 138, in script call
call _start_store
File "renpy/common/00start.rpy", line 106, in script
python hide:
File "D:\Programs\renpy-6.99.3-sdk\renpy\ast.py", line 810, in execute
i()
File "game/script.rpy", line 12, in health_callback
if check_health and Health <= 0:
NameError: global name 'check_health' is not defined
Ren'Py 6.99.8.959
- PyTom
- Ren'Py Creator
- Posts: 16093
- 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: Is there a way to make interruptions based on a variable
Grrr... python callbacks are tricky, even for me. Here's working code that I've actually tested.
Code: Select all
default Health = 42
init python:
check_health = False
def health_callback():
global check_health
if check_health and Health <= 0:
check_health = False
renpy.jump("death")
config.python_callbacks.append(health_callback)
label start:
$ check_health = True
"Alive."
$ Health = 0
"Still alive."
return
label death:
"Pushing up daisies."
return
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
-
- Regular
- Posts: 47
- Joined: Thu Mar 03, 2016 12:53 am
- Completed: Valerie's rest: Scripts and dreams, Countdown to Silence
- Projects: Geas Institute, Adventuring enterprises
- Contact:
Re: Is there a way to make interruptions based on a variable
That worked perfectly, I think all I was missing was the "$ check_health = True" after "label start:"
Thank you very much for your help, and if I'm reading timezone differences correctly sorry for keeping you up so late
Thank you very much for your help, and if I'm reading timezone differences correctly sorry for keeping you up so late
- johandark
- Veteran
- Posts: 355
- Joined: Sat Apr 30, 2016 11:04 am
- Completed: Wild Guards, In Dreams
- Projects: Pact with a witch
- Deviantart: johandarkweb
- Location: Barcelona
- Contact:
Re: Is there a way to make interruptions based on a variable
This post helped me a lot.
I just have a little question about it.
Let´s imagine that apart from "Dying" there´s a point where your "courage" goes below 0 and you have to run at home because you are afraid of everything at any step in the game. So there´s need fo 2 config.python_callbacks.
I´ve tried this code, but it didn´t work.
Any help about it would be apreciated.
Thanks.
I just have a little question about it.
Let´s imagine that apart from "Dying" there´s a point where your "courage" goes below 0 and you have to run at home because you are afraid of everything at any step in the game. So there´s need fo 2 config.python_callbacks.
I´ve tried this code, but it didn´t work.
Code: Select all
init:
image black = ("#fff")
init python:
check_health = False
def health_callback():
global check_health
if check_health and health <= 0:
check_health = False
renpy.jump("death")
config.python_callbacks.append(check_health)
#This one is the tricky, because I don´t know if the config.python_callbacks.append is working well or not.
check_brave = False
def brave_callback():
global check_brave
if check_brave and courage <= 0:
check_brave = False
renpy.jump("coward")
config.python_callbacks.append(check_brave)
label start:
scene black
$ check_health = True
$ check_brave = True
"You are in front of a little wall, do you really think that you can destroy it?"
"You" "Of course I can!"
"You" "Take a sit, and wath me!"
label destroy_wall:
$ d20 = renpy.random.randint(1, 2)
$ destroywall = skill + d20
if d20 >= 2:
"Your skills are [skill] points + your dice result is ([d20]), so your power to destroy the wall is {size=48}{b}[destroywall]{/b}{/size} points."
else:
"Your skills are [skill] points, but unfortunately your dice roll had the worst result {b}([d20]){/b}."
jump fatality
if destroywall >= 30:
jump wall
else:
jump walk
label wall:
"You jumped the wall bitch, you were lucky, I guess."
$ health -= 1
if courage <=10:
$ courage += 5
"You damage your hand just a little bit, but you gain a lot of confidence."
jump abc
label walk:
"You didn´t succeed destroying the wall, get out of here walking scumbag."
$ health -= 3
$ courage -= 20
"Your health is now [health] and your courage is [courage]."
jump abc
label fatality:
"Jajaja, Get back home kiddo, all your blood is on the wall, you are hopeless."
$ health -= 25
$ courage -= 20
"Now your health is [health] and your courage is [courage]."
jump abc
label abc:
"Now you are in abc, bitch."
"Now, try again."
return
label coward:
"You´re filthy pussy coward bastard, so you go back home hiding below your pillow."
label death:
"You´re death, you scumbag, burn in hell! Hahahahaahhahaah... ha..."
return
Thanks.
Re: Is there a way to make interruptions based on a variable
It doesn't seem like you ever set health or courage before attempting to add or subtract from those values.
Re: Is there a way to make interruptions based on a variable
Yeah, also:
you prolly want to review this and you also might put all labels on first indent, it doesn't matter in terms of logic but it looks better.
Code: Select all
$ d20 = renpy.random.randint(1, 2)
Who is online
Users browsing this forum: Andredron, Google [Bot]