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.
I'm very much a beginner attempting my first programming by myself so forgive if it's a simple issue.
I've been attempting to have a variable that switches from true to false and back again at random real-time intervals. I thought I'd be able to use renpy's time function to do it but haven't had any luck using it as described for non-jumping purposes. I decided to make a custom function that would do it instead and have been trying to get it to work. This is what I have so far (no time even involved yet) but I haven't been successful.
The variable is intended to be referenced during choices like a flag eventually.
Here's my code I've been testing with, Eileen in this example only says false (the default value for watched)
init 999 python:
config.developer = True
config.console = True
define e = Character("Eileen")
default watched = False
init python:
currentwatch = False
def swapWatch(currentwatch):
if currentwatch is True:
watched = False
else:
watched = True
# The game starts here.
label start:
scene bg room
show eileen happy
# These display lines of dialogue.
e "[watched]"
e "[watched]"
$ swapWatch(watched)
e "[watched] (should be swapped)"
e "[watched]"
$ swapWatch(watched)
e "[watched] (should be swapped back)"
e "[watched]"
I feel like as a beginner to python I must not quite be understanding how the python section of the code is interacting with the renpy section of the code.
In your code you:
- declared changable global variable 'watched',
- set 'currentwatch' variable to False at every game start,
- created the 'swapWatch' function that takes 'currentwatch' argument.
In 'swapWatch' function:
- if given argument is True, you set the local (related only to this function) variable 'watched' to False,
- overwise, set this local variable to True.
So, try either:
- use global variable 'watched' in 'swapWatch' function, like
label start:
scene bg room
show eileen happy
# These display lines of dialogue.
e "[watched]"
e "[watched]"
#$ swapWatch(watched)
$ watched = not watched
Hey thanks! I wasn't sure if calling the variable something different in the function definition would confuse it, I'm used to javascript where you would've given it a unique placeholder variable. So thank you! I'll try these pieces of code out!