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.
Bruni Multimedia
Regular
Posts: 114 Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:
#1
Post
by Bruni Multimedia » Wed Sep 05, 2018 5:53 am
Hi.
Let's say I have the following variables:
Code: Select all
goofy_1_charm = 0
goofy_2_charm = 0
goofy_3_charm = 0
donald_1_charm = 0
donald_2_charm = 0
donald_3_charm = 0
And I want to use a counter to assign a value to them dinamically:
I tried:
Code: Select all
if cond_1 == True:
$ counter += 1
$ eval("goofy"+str(counter)+"_charm") = value
$ eval("donald"+str(counter)+"_charm") = value
if cond_2 == True:
$ counter += 1
$ eval("goofy"+str(counter)+"_charm") = value
$ eval("donald"+str(counter)+"_charm") = value
However it looks like I can safely use "eval" as a value but I cannot assign to a function call.
Any idea how to work around this?
Last edited by
Bruni Multimedia on Fri Sep 07, 2018 8:07 am, edited 1 time in total.
MaydohMaydoh
Regular
Posts: 165 Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:
#2
Post
by MaydohMaydoh » Wed Sep 05, 2018 8:05 am
You would probably be better using a dictionary.
Code: Select all
goofy = { "charm_1" : 0, "charm_2" : 0, "charm_3" : 0 }
if cond_1:
$ counter += 1
$ goofy["charm_" + str(counter)] = value
or even a list would do,
Code: Select all
goofy_charm = [0, 0, 0]
if cond_1:
$ counter += 1
$ goofy_charm[counter] = value
And remember the first item in the list has an index of 0 not 1. But in your case a dictionary would probably be better as you can easily add more values.
Bruni Multimedia
Regular
Posts: 114 Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:
#3
Post
by Bruni Multimedia » Wed Sep 05, 2018 12:53 pm
Awesome! I shall try that asap.
I wasn't aware of this dictionary thing, it will help me a lot with many future features
Bruni Multimedia
Regular
Posts: 114 Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:
#4
Post
by Bruni Multimedia » Fri Sep 07, 2018 8:07 am
Worked like a charm, thank you very much!
Users browsing this forum: Bing [Bot]