Can someone help me understand Function?
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.
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.
- GeeSeki
- Regular
- Posts: 109
- Joined: Sat Dec 17, 2016 3:39 am
- Projects: A Town Uncovered
- itch: geeseki
- Contact:
Can someone help me understand Function?
I'm trying to fix a problem with my inventory system where everytime I reload the game, the items disappear and the money originally deducted comes back. A post (viewtopic.php?f=8&t=31128) mentioned the use of Functions (https://www.renpy.org/doc/html/screen_a ... l#Function) But I don't understand it at all. Can someone like break it down so that I can understand (I only know the pretty basic stuff) and so that I can possibly use it to fix my inventory?
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Can someone help me understand Function?
You may want to look at this thread of mine from 2 years ago. It needs updating for current best practices (i.e. declaring variables with default rather than just inside the start label), but I hope it teaches you some Python.
viewtopic.php?f=8&t=30788&hilit=inventory
viewtopic.php?f=8&t=30788&hilit=inventory
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
- korova
- Veteran
- Posts: 217
- Joined: Sat Jun 27, 2009 5:15 pm
- Completed: Ivy, Chocolate, Time, Clair Obscur
- Projects: Writing exercises, The House [Nano18]
- Tumblr: korova08
- itch: korova
- Location: Normandie, France
- Contact:
Re: Can someone help me understand Function?
I'm not sure you need functions here but more persistent variables.
Each time you start again the game, variables are re-initialized (put back to the value they had at the beginning of the game)
If you want the values to stay between runs, that what persistent variables do.
you can reed about that here : https://www.renpy.org/doc/html/persistent.html to see if it is what you need
Each time you start again the game, variables are re-initialized (put back to the value they had at the beginning of the game)
If you want the values to stay between runs, that what persistent variables do.
you can reed about that here : https://www.renpy.org/doc/html/persistent.html to see if it is what you need
- GeeSeki
- Regular
- Posts: 109
- Joined: Sat Dec 17, 2016 3:39 am
- Projects: A Town Uncovered
- itch: geeseki
- Contact:
Re: Can someone help me understand Function?
Thanks for that guys, I've read what you've sent me and I think I may know why the items disappear and money goes back to default when I reload. It's because the inventory code that I have is inside an init python block. That's probably why? I'm not 100% sure but so far that's my best bet because looking at the thread from trooper6, it's pretty much what I have coded in.
Though there's something in the code that's messing up the game and I can't find a single thing about it and that's the inventory data being carried over onto another save file. Like, I'll have one save file that has 5 minutes of gameplay, and then I'll have another save file with 1 hour gameplay, and if I earned for example, $1000 in the 1 hour save file and load the 5 minute save file, I'll suddenly have $1000 in that as well.
Though there's something in the code that's messing up the game and I can't find a single thing about it and that's the inventory data being carried over onto another save file. Like, I'll have one save file that has 5 minutes of gameplay, and then I'll have another save file with 1 hour gameplay, and if I earned for example, $1000 in the 1 hour save file and load the 5 minute save file, I'll suddenly have $1000 in that as well.
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Can someone help me understand Function?
Are you using persistent variables?
Also, you could post your code so we could actually see it.
Also, you could post your code so we could actually see it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Can someone help me understand Function?
Also read this if you haven't yet - https://www.renpy.org/doc/html/save_load_rollback.html
Who is online
Users browsing this forum: Google [Bot]
