How do I use list.append and list.remove?[SOLVED]
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.
- TellerFarsight
- Veteran
- Posts: 230
- Joined: Sun Jun 04, 2017 8:09 pm
- Projects: Vora, Secrets Untold
- Location: Toronto, ON
- Contact:
How do I use list.append and list.remove?[SOLVED]
I can't find the documentation on it. Very generally, how do I use this to define a new list variable from an existing list variable?
Last edited by TellerFarsight on Mon Jul 17, 2017 4:51 pm, edited 1 time in total.
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: How do I use list.append and list.remove?
List is a Python thing, so you'd want to check Python Documentation.
Could you explain a bit more what you want? Using an actual example of what you want? What do you mean define a list variable from an existing list variable? When do you want to do that? Why and under what circumstances?
Basically using list.append and list.remove is just:
But if you want to dig into Python a bit more, I'd recommend the free basic Python course from codeacademy.com
Could you explain a bit more what you want? Using an actual example of what you want? What do you mean define a list variable from an existing list variable? When do you want to do that? Why and under what circumstances?
Basically using list.append and list.remove is just:
Code: Select all
default items = []
label start:
$items.append("flowers")
$items.remove("flowers")
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
- TellerFarsight
- Veteran
- Posts: 230
- Joined: Sun Jun 04, 2017 8:09 pm
- Projects: Vora, Secrets Untold
- Location: Toronto, ON
- Contact:
Re: How do I use list.append and list.remove?
I know very generally how to do it in python (I'm actually already partway through codeacademy), I just wasn't sure if there were differences with Ren'Py that I needed to know.
I basically wanted to do just what you showed.
I basically wanted to do just what you showed.
Code: Select all
default mainfolder = [{"sender":"","subject":"","email":"",},]
label start:
$ mainfolder.append({"sender":"Eileen","subject":"Maily Mail","email":"Bla Bla Bla"}) # What kind of brackets do I use here? I want to append a *list* of items
"Now if I check mail, I'll see one from Eileen!"
$ mainfolder.append({"sender":"Lucy","subject":"MAAIILL","email":"Bleep Bloop"})
"Now if I checked the mail, I would see both of them!"
$ mainfolder.remove({"sender":"Eileen","subject":"Maily Mail","email":"Bla Bla Bla"})
"Oh! Someone deleted Eileen's email! A mystery is afoot!"
Re: How do I use list.append and list.remove?
I'm not quite sure how you envision this working. As currently written, your list is a list dictionaries, not a list of lists. That said, you can append to the lists in your list directly.
Etc. However from what you're trying to do it might be better to use class objects, if you're willing to familiarize yourself with them.
Alternatively, you could default your mainfolder to an empty list and access your current structure individually (e.g., mainfolder[0]["sender"] would access "Eileen").
Code: Select all
default main = [[], [], []] #has empty lists, one each for sender, subject, etc.
main[0].append("Lucy")
main[1].append("MAAILL")
Alternatively, you could default your mainfolder to an empty list and access your current structure individually (e.g., mainfolder[0]["sender"] would access "Eileen").
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: How do I use list.append and list.remove?
There are lots of ways of doing this. I think the easiest way to do it is to make an email class that you then have in your main folder.
You may want to read through this thread I made two years ago which explains how to make an inventory using different methods. What you are doing, after all, is just an inventory. But instead of swords, you have emails and instead of a backpack you have a manifolder
viewtopic.php?f=8&t=30788
You may want to read through this thread I made two years ago which explains how to make an inventory using different methods. What you are doing, after all, is just an inventory. But instead of swords, you have emails and instead of a backpack you have a manifolder
viewtopic.php?f=8&t=30788
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
- TellerFarsight
- Veteran
- Posts: 230
- Joined: Sun Jun 04, 2017 8:09 pm
- Projects: Vora, Secrets Untold
- Location: Toronto, ON
- Contact:
Re: How do I use list.append and list.remove?
Thanks for the advice, guys! Looks like I have a lot of studying ahead of me.
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: How do I use list.append and list.remove?
I learned how to do python by using ren'py. Needless to say, I had problems distinguishing between ren'py script and actual python code at first. Don't even get me started with screen language.
There are some "best practices" when handling data:
- if the data is a heterogenous package that belongs together, use a class
- if the data homogenous and will be iterated over, use a list
- if the data is fixed and stored, not to be changed, use tuples
- if you need to translate data to other data, use dictionaries
So for example you have a class called Email, which has various variables like sender, subject, text, date. It also has recipient, which is a list, and a dictionary of custom meta fields.
Honestly I almost never use tuples because they are exactly like lists, only write-protected.
There are some "best practices" when handling data:
- if the data is a heterogenous package that belongs together, use a class
- if the data homogenous and will be iterated over, use a list
- if the data is fixed and stored, not to be changed, use tuples
- if you need to translate data to other data, use dictionaries
So for example you have a class called Email, which has various variables like sender, subject, text, date. It also has recipient, which is a list, and a dictionary of custom meta fields.
Honestly I almost never use tuples because they are exactly like lists, only write-protected.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: How do I use list.append and list.remove?
tuples are also faster and they are very good for things like: lists of days, lists of months, etcMilkymalk wrote: Honestly I almost never use tuples because they are exactly like lists, only write-protected.
you also forgot sets, which are not ordered, but don't allow duplicates.
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
- TellerFarsight
- Veteran
- Posts: 230
- Joined: Sun Jun 04, 2017 8:09 pm
- Projects: Vora, Secrets Untold
- Location: Toronto, ON
- Contact:
Re: How do I use list.append and list.remove?
Alright so I've gone and learned some python, and now I'm back trying to solve this problem I originally had.
Here's a data structure I've got. It's kind of ridiculous, but this is exactly what I need and it works. It's a list of dictionaries, and one of the items in the dictionary is another list of dictionaries.
Now, I want to add another item (another list of dictionaries) to day0map1[0]["actions_list"], *at* index 0.
I've tried
which works, but obviously appends it to the end of the list instead of inserting it at index 0, but if I try to use list.insert, it seems to get confused like this:
Any ideas?
Also, if it helps, I had tried this earlier:
Edit: The mail data I was asking about before was solved by making it a class like trooper6 said.
Edit 2: Oops. Dumb mistake, but I figured it out
Here's a data structure I've got. It's kind of ridiculous, but this is exactly what I need and it works. It's a list of dictionaries, and one of the items in the dictionary is another list of dictionaries.
Code: Select all
day0map2 = [
{"place":"Shinjuku",
"photo":"shinjuku_evening_photo",
"icon1":None,
"icon2":None,
"actions_list":
[
{"act_name":"Look around", "call":"day0shinjukulook"},
{"act_name":"Listen to people here", "call":"day0map2shinjukulisten"},
{"act_name":"Talk with your party", "call":"day0party"},
]
},
{#more stuff in the list, but you get the idea}]
# such that in PyShell
>>> print day0map1[0]["actions_list"][1]["call"]
day0map2shinjukulisten
I've tried
Code: Select all
day0map1[0]["actions_list"].append({"act_name":"Yuzu", "jump":"day0map2shinjukuyuzu"})
Code: Select all
>>> day0map1[0]["actions_list"].insert([0], {"act_name":"Yuzu", "jump":"day0map2shinjukuyuzu"})
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: an integer is required
Also, if it helps, I had tried this earlier:
Code: Select all
>>> day0map1.insert([0]["actions_list"][0], {"act_name":"Yuzu", "jump":"day0map2shinjukuyuzu"})
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: list indices must be integers, not str
Edit 2: Oops. Dumb mistake, but I figured it out
Code: Select all
day0map1[0]["actions_list"].insert(0, {"act_name":"Yuzu", "jump":"day0map2shinjukuyuzu"})
# I wasn't supposed to put square brackets around the insert index
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: How do I use list.append and list.remove?
Why don't you use a real class?
>>> print(places[0].actions[0].call)
"day0shinjukulook"
Code: Select all
class Place(object):
def __init__(self, name, photo, icons=[], actions=[]):
self.name = name
self.photo = photo
self.icons = icons
self.actions = actions
class Placeaction(object):
def __init__(self, name, call):
self.name = name
self.call = call
places = []
action1 = Placeaction("Look around", "day0shinjukulook")
action2 = Placeaction("Listen to people here", "day0map2shinjukulisten")
action3 = Placeaction("Talk with your party", "day0party")
places.append(Place("Shinjuku", "shinjuku_evening_photo", actions=[action1, action2, action3]))
"day0shinjukulook"
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
- TellerFarsight
- Veteran
- Posts: 230
- Joined: Sun Jun 04, 2017 8:09 pm
- Projects: Vora, Secrets Untold
- Location: Toronto, ON
- Contact:
Re: How do I use list.append and list.remove?[SOLVED]
I made this data structure quite a while ago, and I just wanted to make sure I knew how to manipulate it. I might change it to a class later.
Who is online
Users browsing this forum: Google [Bot], snotwurm