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.
-
bebeesun
- Regular
- Posts: 30
- Joined: Sat Jan 23, 2016 5:20 pm
-
Contact:
#1
Post
by bebeesun » Fri Jan 29, 2016 4:57 am
im back again and there's something that i need help with that is very simple. but i cant figure it out bc i just learned about classes today so im new to it. im trying to make a menu that displays a list of characters and how much they are in love with the main character....
Code: Select all
init python:
class Lover():
def __init__(self, name, points):
self.name = name
self.points = points
lovers.append(self)
screen lovers:
modal True
$ lovers= [name for name in lovers]
frame:
xpos 942
ypos 650
xsize 510
ysize 405
vbox:
label "lovers"
if name in lovers:
text name.name + #points go here....
textbutton "Close" action Hide("lovers")
i just want to be able to display the characters points next to the name thats all.
-
Iylae
- Regular
- Posts: 73
- Joined: Sat Jan 09, 2016 6:57 am
- Location: Cornwall, UK
-
Contact:
#2
Post
by Iylae » Fri Jan 29, 2016 5:12 am
Try the following:
Code: Select all
init python:
lovers = [] #initialise the lovers variable as an array/list using []
class Lover():
def __init__(self, name, points):
self.name = name
self.points = points
lovers.append(self)
Lover("Ariadne",0) #create a lover
Lover("Belle",0) #create another lover
screen lovers():
modal True
frame:
# I removed the pos vars because it wouldn't display on my resolution
vbox:
label "lovers"
for lover in lovers: # note the change here.
text lover.name + ": " + str(lover.points) # as lover.points is an integer, we use str() to turn it into a string
textbutton "Close" action Hide("lovers")
label start:
show screen lovers # actually show the screen
"" # waits for the user to click before ending
If we are what we repeatedly do, then good coding is not an act, but a habit
-
bebeesun
- Regular
- Posts: 30
- Joined: Sat Jan 23, 2016 5:20 pm
-
Contact:
#3
Post
by bebeesun » Fri Jan 29, 2016 5:24 am
thank you so much!!
-
bebeesun
- Regular
- Posts: 30
- Joined: Sat Jan 23, 2016 5:20 pm
-
Contact:
#4
Post
by bebeesun » Fri Jan 29, 2016 5:42 am
wait i have another question...they dont show up on the list at the same time. only one does.
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#5
Post
by xela » Fri Jan 29, 2016 6:17 am
bebeesun wrote:wait i have another question...they dont show up on the list at the same time. only one does.
They should both show up, but that is a bad code that will fail you in a real gameplay on saving, try:
Code: Select all
init:
default lovers = []
python:
class Lover(object):
def __init__(self, name, points):
self.name = name
self.points = points
lovers.append(self)
screen lovers():
modal True
frame:
has vbox
label "lovers"
for lover in lovers: # note the change here.
text lover.name + ": " + str(lover.points) # as lover.points is an integer, we use str() to turn it into a string
textbutton "Close" action Hide("lovers")
label start:
$ Lover("Ariadne", 0) # create a lover
$ Lover("Belle", 0) # create another lover
show screen lovers # actually show the screen
pause # waits for the user to click before ending
That prolly won't fix whatever might be causing the issue with the other actor not showing but it will save properly.
Like what we're doing? Support us at:

-
bebeesun
- Regular
- Posts: 30
- Joined: Sat Jan 23, 2016 5:20 pm
-
Contact:
#6
Post
by bebeesun » Fri Jan 29, 2016 6:31 am
thankk you!! your code actually fixed the problem. that also happened to me last time i tried making a menu idk what im doing to make that happen but thank you!!
-
Iylae
- Regular
- Posts: 73
- Joined: Sat Jan 09, 2016 6:57 am
- Location: Cornwall, UK
-
Contact:
#7
Post
by Iylae » Fri Jan 29, 2016 6:57 am
Honestly I need to post-it note the default keyword to my monitor. Thanks for picking up on that xela.
... Also instantiating variables in start: and not in init:
Last edited by
Iylae on Fri Jan 29, 2016 7:04 am, edited 1 time in total.
If we are what we repeatedly do, then good coding is not an act, but a habit
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#8
Post
by xela » Fri Jan 29, 2016 7:02 am
Iylae wrote:Honestly I need to post-it note the default keyword to my monitor. Thanks for picking up on that xela.
NP.
+ You shouldn't instantiate classes in the init, you may run into a similar issue with saving/loading.
Like what we're doing? Support us at:

Users browsing this forum: Bing [Bot], Google [Bot]