List or Sets

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.
Post Reply
Message
Author
User avatar
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

#1 Post by Wide Mouth Ink »

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.

User avatar
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

#2 Post by PyTom »

This probably means you didn't initialize the list in the right place. Did you do?

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
Software > Drama • https://www.patreon.com/renpytom

User avatar
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

#3 Post by Wide Mouth Ink »

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.

Code: Select all

init:
    $ bag = []
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.

User avatar
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

#4 Post by PyTom »

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

Code: Select all

default bag = [ ]
(and similarly with the other variables), or move the assignments to after label start.

Code: Select all

label start:
     $ bag = [ ]
Do this, and your problems will likely vanish. (Well, this problem, anyway.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
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

#5 Post by Wide Mouth Ink »

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?

User avatar
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

#6 Post by PyTom »

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
Software > Drama • https://www.patreon.com/renpytom

User avatar
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

#7 Post by Wide Mouth Ink »

Just that, huh. Alright, thanks again.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]