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.
magnifique
Newbie
Posts: 6 Joined: Tue May 27, 2014 7:10 am
Deviantart: wrothsloth
Contact:
#1
Post
by magnifique » Thu Sep 22, 2022 3:56 pm
This is probably a stupid question, but how can I make something like this?
Code: Select all
$ event_chara = someone
$ [event_chara]_points += 10 #which results in someone_points += 10
TIA
Last edited by
magnifique on Thu Sep 22, 2022 10:03 pm, edited 1 time in total.
enaielei
Veteran
Posts: 293 Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:
#2
Post
by enaielei » Thu Sep 22, 2022 8:52 pm
setattr/getattr
Code: Select all
$ someone_points = 0
$ x_points = "someone_points"
$ setattr(store, x_points, getattr(store, x_points) + 10)
renpy.python.py_exec
Code: Select all
$ someone_points = 0
$ x_points = "someone_points"
$ renpy.python.py_exec("{} += 10".format(x_points))
dict
Code: Select all
$ points = dict(someone=0)
$ x = "someone"
$ points[x] += 10
OOP
Code: Select all
init python:
class Someone():
def __init__(self, points=0):
self.points = points
label start:
$ someone = Someone()
$ x = someone
$ x.points += 10
magnifique
Newbie
Posts: 6 Joined: Tue May 27, 2014 7:10 am
Deviantart: wrothsloth
Contact:
#3
Post
by magnifique » Thu Sep 22, 2022 10:03 pm
Thanks a lot! Making a dict seems like the most straight forward method
Users browsing this forum: Ahrefs [Bot] , Semrush [Bot]