List or Sets
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.
- Wide Mouth Ink
- Regular
- Posts: 38
- Joined: Wed Jan 07, 2015 12:02 pm
- Completed: None for now
- Projects: Endless Halls
- Tumblr: WideMouthInk
- Deviantart: WideMouthInk
- Contact:
List or Sets
I'm getting a bit annoyed that Ren'Py just plain removes the items from my inventory 'list' everytime I reload the script for my game.
This has made testing a pain in the ass, especially when you're trying to fix up the displays of an inventory menu.
Now I know there's another variable that's refered to as 'set' that pretty much works the same as a 'list', but it doesn't allow two items of the same name to be on it's version of a list.
My main concern is if using a 'set' instead of a 'list' would help me from having to close the game and open again everytime Ren'Py forgets what it's supposed to be holding during testing. I'm also curious what the differences between the two are.
If there's no real difference it seems I'll just have to resort to using the init trick.
This has made testing a pain in the ass, especially when you're trying to fix up the displays of an inventory menu.
Now I know there's another variable that's refered to as 'set' that pretty much works the same as a 'list', but it doesn't allow two items of the same name to be on it's version of a list.
My main concern is if using a 'set' instead of a 'list' would help me from having to close the game and open again everytime Ren'Py forgets what it's supposed to be holding during testing. I'm also curious what the differences between the two are.
If there's no real difference it seems I'll just have to resort to using the init trick.
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: List or Sets
This probably means you didn't initialize the list in the right place. Did you do?
?
If you didn't create the inventory in the right place, it won't be saved and you'll get the problem you're experiencing.
Code: Select all
default inventory = [ ]
If you didn't create the inventory in the right place, it won't be saved and you'll get the problem you're experiencing.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- Wide Mouth Ink
- Regular
- Posts: 38
- Joined: Wed Jan 07, 2015 12:02 pm
- Completed: None for now
- Projects: Endless Halls
- Tumblr: WideMouthInk
- Deviantart: WideMouthInk
- Contact:
Re: List or Sets
If by that, you mean putting it in an 'init:' block. I have. for some reason, out of all the variables, that's the one that just plain resets during testing.
If you mean using that 'default' instead of the usual '$' or something else entirely, then no.
This are pretty much how I set it up along with a 10 dozen other variables I'm using for the functions of the game.
If you mean using that 'default' instead of the usual '$' or something else entirely, then no.
Code: Select all
init:
$ bag = []
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: List or Sets
So the problem here is that variables defined in init aren't saved. This is so characters, transitions, transforms, functions, modules, etc. aren't saved. You either have to use
(and similarly with the other variables), or move the assignments to after label start.
Do this, and your problems will likely vanish. (Well, this problem, anyway.)
Code: Select all
default bag = [ ]
Code: Select all
label start:
$ bag = [ ]
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- Wide Mouth Ink
- Regular
- Posts: 38
- Joined: Wed Jan 07, 2015 12:02 pm
- Completed: None for now
- Projects: Endless Halls
- Tumblr: WideMouthInk
- Deviantart: WideMouthInk
- Contact:
Re: List or Sets
The strange thing is, the list is the only one that was affected...
Well, I added the list to the start, which did fix it. So, thanks Py'Tom.
At least this can serve as a learning experience for coding.
Still curious if there's any real differences with 'lists' and 'sets', or is it mostly a preference thing?
Well, I added the list to the start, which did fix it. So, thanks Py'Tom.
At least this can serve as a learning experience for coding.
Still curious if there's any real differences with 'lists' and 'sets', or is it mostly a preference thing?
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: List or Sets
Basically, lists preserve order and allow duplication. Sets do not - an item can only be in a set once.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- Wide Mouth Ink
- Regular
- Posts: 38
- Joined: Wed Jan 07, 2015 12:02 pm
- Completed: None for now
- Projects: Endless Halls
- Tumblr: WideMouthInk
- Deviantart: WideMouthInk
- Contact:
Re: List or Sets
Just that, huh. Alright, thanks again.
Who is online
Users browsing this forum: No registered users