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.
-
Reikun
- Miko-Class Veteran
- Posts: 565
- Joined: Tue Dec 20, 2011 9:57 pm
- Completed: Mnemonic Devices, Ciikos Bridge, Helena's Flowers, The Madness
- Projects: Fox in the Hollyhocks
- Organization: skyharborr
- itch: skyharborr
-
Contact:
#1
Post
by Reikun » Mon Jun 06, 2022 12:34 am
I tried searching but couldn't find an answer... This feels like it should have a simple solution but I'm not sure what I'm doing wrong (haven't touched renpy in a long time too so that doesn't help)
Anyway...
I'm using a dictionary to track how suspicious an NPC feels about other characters
Code: Select all
#in a separate file
init python:
#dict for Lucius
lsus = {
"Ciro" : 0,
"Lucius" : 0,
"Bugra" : 1
}
find_lsus = max(lsus, key=lsus.get) #finds which character Lucius is most suspicious of
#these two are test variables so I can see if their values actually changed
lsus0 = lsus["Ciro"]
lsus3 = lsus["Bugra"]
I tried to make a sample menu to see if I could add more suspicion:
Code: Select all
#in a separate file that's called from script.rpy
menu:
"Add some suspicion."
"+5 Ciro":
$ lsus["Ciro"] += 5
"Ciro = [lsus0]"
"+3 Bugra":
$ lsus["Bugra"] += 3
"Bugra = [lsus3]"
It keeps giving me the default values though (0 for Ciro and 1 for Bugra). Not sure what I'm doing wrong here


✧

✧
fastest way to contact me: DM @skyharborr on twitter
-
m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
-
Contact:
#2
Post
by m_from_space » Mon Jun 06, 2022 5:14 am
Well, you obviously don't realize that the block after "init python:" is only executed once when you start the game. So lsus0 and lsus3 are never updated of course, they are not references or pointers if you thought that.
I don't quite get why you need those variables, because you can just check for the dict's contents by doing:
Code: Select all
"Bugra = [lsus[Bugra]]" # this is the way you do it in renpy, you don't need " or '
-
Reikun
- Miko-Class Veteran
- Posts: 565
- Joined: Tue Dec 20, 2011 9:57 pm
- Completed: Mnemonic Devices, Ciikos Bridge, Helena's Flowers, The Madness
- Projects: Fox in the Hollyhocks
- Organization: skyharborr
- itch: skyharborr
-
Contact:
#3
Post
by Reikun » Mon Jun 06, 2022 6:18 am
Thank you! Yes, I didn't understand that about init python. I have figured it out now (and ended up switching from just a dictionary to using a class). Also thank you for showing me how to get the dictionary contents in renpy code.

✧

✧
fastest way to contact me: DM @skyharborr on twitter
Users browsing this forum: Bing [Bot]